Skip to content

Commit

Permalink
halfway there
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Oct 30, 2023
1 parent 3f89344 commit 68f2361
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const url = require('url');

const cache = new Map();

const _request = (method) => (...args) => retry(() => rpn[method](...args), { retries: 0 });
const _request = (method) => (...args) => retry(() => rpn[method](...args), { retries: 5, randomize: false, factor: 1.5 });
const request = {
get: _request('get'),
post: _request('post'),
Expand Down
33 changes: 30 additions & 3 deletions test/fn/create-users.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ const userPrompt = rewire('../../src/lib/user-prompt');
const readLine = require('readline-sync');
const mockTestDir = testDir => sinon.stub(environment, 'pathToProject').get(() => testDir);

describe('create-users', () => {
describe('create-users', function () {
this.timeout(15000);

beforeEach(() => {
createUsers.__set__('userPrompt', userPrompt);
sinon.stub(environment, 'isArchiveMode').get(() => false);
Expand Down Expand Up @@ -86,7 +88,15 @@ describe('create-users', () => {

it('should create user with existent place and not implemented user-info endpoint', () => {
mockTestDir(`data/create-users/existing-place`);
api.giveResponses({ status: 404, body: { code: 404, error: 'not_found' } }, { body: {} });
api.giveResponses(
{ status: 404, body: { code: 404, error: 'not_found' } },
{ status: 404, body: { code: 404, error: 'not_found' } },
{ status: 404, body: { code: 404, error: 'not_found' } },
{ status: 404, body: { code: 404, error: 'not_found' } },
{ status: 404, body: { code: 404, error: 'not_found' } },
{ status: 404, body: { code: 404, error: 'not_found' } },
{ body: {} },
);
const todd = {
username: 'todd',
password: 'Secret_1',
Expand All @@ -108,6 +118,11 @@ describe('create-users', () => {
.then(() => /* when */ createUsers.execute())
.then(() => {
assert.deepEqual(api.requestLog(), [
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'POST', url: '/api/v1/users', body: todd },
]);
Expand Down Expand Up @@ -220,7 +235,14 @@ describe('create-users', () => {
},
};

api.giveResponses({ status: 500, body: { code: 500, error: 'boom' } } );
api.giveResponses(
{ status: 500, body: { code: 500, error: 'boom' } },
{ status: 500, body: { code: 500, error: 'boom' } },
{ status: 500, body: { code: 500, error: 'boom' } },
{ status: 500, body: { code: 500, error: 'boom' } },
{ status: 500, body: { code: 500, error: 'boom' } },
{ status: 500, body: { code: 500, error: 'boom' } },
);
const qs = {
facility_id: todd.place,
role: JSON.stringify(todd.roles),
Expand All @@ -232,6 +254,11 @@ describe('create-users', () => {
assert.deepEqual(err.error, { code: 500, error: 'boom' });
assert.deepEqual(api.requestLog(), [
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
{ method: 'GET', url: '/api/v1/users-info?' + querystring.stringify(qs), body: {} },
]);
});
});
Expand Down

0 comments on commit 68f2361

Please sign in to comment.