mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
tests(api): Port over new integration helper from develop
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
/* eslint-disable no-use-before-define */
|
/* eslint-disable no-use-before-define */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
set,
|
assign,
|
||||||
each,
|
each,
|
||||||
isEmpty,
|
isEmpty,
|
||||||
|
set,
|
||||||
times,
|
times,
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
import { MongoClient as mongo } from 'mongodb';
|
import { MongoClient as mongo } from 'mongodb';
|
||||||
@@ -23,6 +24,17 @@ const ROUTES = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ApiUser {
|
||||||
|
constructor (options) {
|
||||||
|
assign(this, options);
|
||||||
|
|
||||||
|
this.get = _requestMaker(this, 'get');
|
||||||
|
this.post = _requestMaker(this, 'post');
|
||||||
|
this.put = _requestMaker(this, 'put');
|
||||||
|
this.del = _requestMaker(this, 'del');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sets up an abject that can make all REST requests
|
// Sets up an abject that can make all REST requests
|
||||||
// If a user is passed in, the uuid and api token of
|
// If a user is passed in, the uuid and api token of
|
||||||
// the user are used to make the requests
|
// the user are used to make the requests
|
||||||
@@ -94,7 +106,9 @@ export function generateUser (update = {}) {
|
|||||||
confirmPassword: password,
|
confirmPassword: password,
|
||||||
}).then((user) => {
|
}).then((user) => {
|
||||||
_updateDocument('users', user, update, () => {
|
_updateDocument('users', user, update, () => {
|
||||||
resolve(user);
|
let apiUser = new ApiUser(user);
|
||||||
|
|
||||||
|
resolve(apiUser);
|
||||||
});
|
});
|
||||||
}).catch(reject);
|
}).catch(reject);
|
||||||
});
|
});
|
||||||
@@ -277,7 +291,6 @@ function _updateDocument (collectionName, doc, update, cb) {
|
|||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO use config for db url?
|
|
||||||
mongo.connect('mongodb://localhost/habitrpg_test', (connectErr, db) => {
|
mongo.connect('mongodb://localhost/habitrpg_test', (connectErr, db) => {
|
||||||
if (connectErr) throw new Error(`Error connecting to database when updating ${collectionName} collection: ${connectErr}`);
|
if (connectErr) throw new Error(`Error connecting to database when updating ${collectionName} collection: ${connectErr}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user