describe('GET /api/v1/user/:user_selector/location', () => { it('should return history of location', async () => { await authenticatedRequest .get('/api/v1/user/john/location') .query({ from: '2018-04-02 04:41:09', to: '2019-04-02 04:41:09', }) .expect('Content-Type', /json/) .expect(200) .then((res) => { res.body.forEach((location) => { expect(location).to.have.property('latitude'); expect(location).to.have.property('longitude'); expect(location).to.have.property('user_id', '0cd30aef-9c4e-4a23-88e3-3547971296e5'); }); }); }); });
describe('GET /api/v1/message', () => { it('should get messages', async () => { await authenticatedRequest .get('/api/v1/message') .query({ take: 1, }) .expect('Content-Type', /json/) .expect(200) .then((res) => { expect(res.body).to.deep.equal([ { id: '247b1dd0-6fab-47a8-a9c8-1405deae0ae8', sender_id: '0cd30aef-9c4e-4a23-88e3-3547971296e5', receiver_id: null, file: null, text: 'What time is it ?', is_read: true, created_at: '2019-02-12T07:49:07.556Z', }, ]); }); }); });
it('should get all users with pagination', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ page: 2, perPage: 1 }) .expect(httpStatus.OK) .then(async (res) => { delete dbUsers.jonSnow.password; expect(res.body).to.be.an('array'); expect(res.body[0]).to.be.an('object'); expect(res.body).to.have.lengthOf(1); expect(res.body[0].name).to.be.equal('Jon Snow'); }); });
it('should filter users', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ email: dbUsers.jonSnow.email }) .expect(httpStatus.OK) .then(async (res) => { delete dbUsers.jonSnow.password; const john = await format(dbUsers.jonSnow); // before comparing it is necessary to convert String to Date res.body[0].createdAt = new Date(res.body[0].createdAt); const includesjonSnow = some(res.body, john); expect(res.body).to.be.an('array'); expect(res.body).to.have.lengthOf(1); expect(includesjonSnow).to.be.true; }); });
step('check unspent transaction from address 1', () => { return Promise.resolve() .then(() => { return supertest(context.httpServer1.app) .get('/blockchain/transactions/unspent') .query({ address: context.address1 }) .expect(200) .expect((res) => { assert.equal(res.body.length, 3, `Expected unspent transactions of address '${context.address1}' to be '3'`); }); }); });
it('should report error when pagination\'s parameters are not a number', () => { return request(app) .get('/v1/users') .set('Authorization', `Bearer ${adminAccessToken}`) .query({ page: '?', perPage: 'whaat' }) .expect(httpStatus.BAD_REQUEST) .then((res) => { const { field } = res.body.errors[0]; const { location } = res.body.errors[0]; const { messages } = res.body.errors[0]; expect(field).to.be.equal('page'); expect(location).to.be.equal('query'); expect(messages).to.include('"page" must be a number'); return Promise.resolve(res); }) .then((res) => { const { field } = res.body.errors[1]; const { location } = res.body.errors[1]; const { messages } = res.body.errors[1]; expect(field).to.be.equal('perPage'); expect(location).to.be.equal('query'); expect(messages).to.include('"perPage" must be a number'); }); });
it( "deleteboard of existing user. Returns 200", function ( done ) { server .get( basePath ) .query( { authorid: userid, delete: previewFolder } ) .expect( 200, done ); } );
it('should redirect to callback url with an error and keeping state when calling authorize endpoint with an invalid response type', async () => { const res = await request(service.requestHandler) .get('/authorize') .query('response_type=invalid_response_type&redirect_uri=http://example.com/callback&scope=dummy_scope&state=state123&client_id=abcecedf') .redirects(0) .expect(302); expect(res.headers.location).toMatch('http://example.com/callback?error=unsupported_response_type&error_description=The+authorization+server+does+not+support+obtaining+an+access+token+using+this+response_type.&state=state123'); });
it( "load an unexisting user board data. Returns 404 and Content-Length:0", function ( done ) { server .get( basePath ) .query( { userid: crypto.createHash( 'md5' ).update( randomwords() ).digest( "hex" ), load: previewFolder } ) .expect( 404 ) .expect( 'Content-Length', '0', done ); } );
it( "getlist of unexisting user. Returns 200", function ( done ) { server .get( basePath ) .query( { getlist: 'unexisting user' + crypto.createHash( 'md5' ).update( randomwords() ).digest( "hex" ), } ) .expect( 200, done ); } );
it( "load an existing user board data. Returns data and 200", function ( done ) { server .get( basePath ) .query( { userid: userid, load: previewFolder } ) .expect( 200 ) .expect( 'params.part = 0 ~` partmax != partparams.part != 0 ~` partmax != partparams.part != 0 ~` partmax = part' ) .expect( 'Content-Length', '105', done ); } );
it( "deleteboard with illigal deletesession parameter. Returns 500 for nodejs; 200 for PHP", function ( done ) { server .get( basePath ) .query( { authorid: '.', delete: '..' } ) .expect( 500, done ); } );