it('should return correct execution response', () => { fetchMock.mock( fakeExecuteAfmUri, { status: 200, body: getPollingResponseBody() } ); return createExecuteAfm().getExecutionResponse('myFakeProjectId', getExecution()) .then((responses: Execution.IExecutionResponse) => { expect(responses).toEqual(getExecutionResponse()); }); });
it('should resolve false if user logged in but project not available', () => { const projectId = 'myProject'; const profileId = 'asdf1234'; const profileUri = `/gdc/account/profile/${profileId}`; fetchMock.mock( '/gdc/account/profile/current', { status: 200, body: JSON.stringify({ accountSetting: { links: { self: profileUri } } }) } ); fetchMock.mock( `/gdc/account/profile/${profileId}/projects?offset=0&limit=100`, { status: 200, body: JSON.stringify({ projects: { paging: { offset: 0, limit: 100, totalCount: 2 }, items: [ { project: { links: { self: '/gdc/projects/differentproject' } } }, { project: { links: { self: '/gdc/projects/anotherproject' } } } ] } }) } ); return expect(createUser().isLoggedInProject(projectId)).resolves.toEqual(false); });
it('Buffers are always clear of previously buffered changes', async () => { fetchMock.mock('*', { body: { settings: {} }, }); const { uiSettingsApi } = setup(); uiSettingsApi.batchSet('foo', 'bar'); uiSettingsApi.batchSet('bar', 'foo'); await uiSettingsApi.batchSet('bar', 'box'); expect(fetchMock.calls()).toMatchSnapshot('two requests, second only sends bar, not foo'); });
it('should return an array of dataSets', () => { fetchMock.mock( '/gdc/md/myFakeProjectId/query/datasets', { status: 200, body: JSON.stringify({ query: { entries: [{}, {}] } }) } ); return createProject().getDatasets('myFakeProjectId').then((result: any) => { expect(result.length).toBe(2); }); });
it('should return rejected promise if 400 returned from backend', () => { fetchMock.mock( using2Uri, { status: 400, body: JSON.stringify({}) } ); return createMd().getObjectUsingMany(projectId, objects, { types }).then(() => { throw new Error('Should reject the promise on 400 response'); }).catch((err: any) => { expect(err.response.status).toBe(400); }); });
it('should update user\'s settings', () => { expect.assertions(1); const userId = 'USER_ID'; fetchMock.mock( `/gdc/account/profile/${userId}/settings`, { status: 400, body: '' } ); return createUser().updateProfileSettings(userId, []).then(null, (err) => { return expect(err.response.status).toBe(400); }); });
it('should throw error on second polling when num of dimensions is 3', () => { fetchMock.mock( fakeExecuteAfmUri, { status: 200, body: getPollingResponseBody(3) } ); return createExecuteAfm().executeAfm('myFakeProjectId', getExecution()) .catch((error) => { expect(error.name).toEqual('Invariant Violation'); expect(error.message).toEqual('3 dimensions are not allowed. Only 1 or 2 dimensions are supported.'); }); });
it('should get and then clear the apiKey', function(done) { fetchMock.mock( (url, opts) => opts.body.indexOf('getApiKey') !== -1, '{"data": {"result": "baz"}}', {name: 'getApiKey'} ) fetchMock.mock( (url, opts) => opts.body.indexOf('clearApiKey') !== -1, '{"data": {"success": true}}', {name: 'clearApiKey'} ) this.api.getApiKey('foo', 'bar').then((apiKey) => { should(apiKey).equal('baz') should(fetchMock.calls('getApiKey')).length(1) should(this.api._httpOptions.headers).have.property('apiKey').eql('baz') this.api.clearApiKey().then(() => { should(this.api._httpOptions.headers).not.have.property('apiKey') done() }) }) })
it('should return correct number of entries', () => { fetchMock.mock( '/gdc/md/myFakeProjectId/availablefacts', { status: 200, body: JSON.stringify({ entries: [{ link: 'm1' }, { link: 'm2' }] }) } ); return createMd().getAvailableFacts('myFakeProjectId').then((result: any) => { expect(result.length).toBe(2); }); });
it('should return correct number of entries', () => { fetchMock.mock( '/gdc/md/myFakeProjectId/drillcrosspaths', { status: 200, body: JSON.stringify({ drillcrosspath: { links: [{ link: 'a1' }, { link: 'a2' }] } }) } ); return createMd().getAvailableAttributes('myFakeProjectId').then((result: any) => { expect(result.length).toBe(2); }); });