describe('API :: POST /api/users', () => { context('when sent data is ok', () => { it('creates and returns 201 and the new user', async () => { const { body } = await request() .post('/api/users') .send({ name: 'New User' }) .expect(201); expect(body.id).to.exist; expect(body.name).to.equal('New User'); expect(body).to.have.all.keys('id', 'name'); }); }); context('when name is missing', () => { it('does not create and returns 400 with the validation error', async () => { const { body } = await request() .post('/api/users') .expect(400); expect(body.type).to.equal('ValidationError'); expect(body.details).to.have.lengthOf(1); expect(body.details[0].message).to.equal('"name" is required'); }); }); });
expect(dbUser).to.have.all.keys('name'); }); });
this.When(/^I get data of "([^"]*)" user$/, function (uid, callback) { request(app) .get('/v2/admin/users/' + uid) .set('Content-Type', 'application/json') .use(this.setAuthorizationHeader(this.uid)) .expect('Content-Type', /json/) .expect(function (res) { expect(res.body).to.contain.all.keys(ofAnUserObject) this.myUser = res.body }.bind(this)) .expect(200, callback) })
it('returns default tasks correctly', function () { const {tasks} = getTasks(); expect(tasks).to.have.length(6); tasks.forEach((task) => { expect(task).to.include.all.keys('id', 'task', 'enabled', 'title'); }); });
it.skip('GET should get a company with id', function(done) { chai.request(server) .get('/v1/companies/'+DUMMY_COMPANY.id) .set('Authorization', global.HEADER_TOKEN) .end((err, res) => { expect(err).to.be.null; expect(res.body.success).to.be.true; expect(res.body.company).to.be.an('object').that.include.all.keys('id', 'name'); expect(res.status).to.be.equal(200); done(); }); })
describe('var:schema', () => { it('check if it\'s valid parsed schema', () => { expect(schema).to.be.an('object').and.to.contain.all.keys('kind', 'definitions'); expect(schema.kind).to.be.a('string').and.to.be.equal('Document'); expect(schema.definitions).to.be.an('array'); }); });
it("decode data for ABIEncoderV2 abi", () => { abiDecoder.addABI(abiV2); const testData = "0xd4f8f1310000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002a000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000050a5cf333fc36a18c8f96b1d1e7a2b013c6267ac000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046dccf96fe3f3beef51c72c68a1f3ad9183a6561000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000254dffcd3277c0b1660f6d42efbb754edababc2b00000000000000000000000000000000000000000000000000000000000f4240000000000000000000000000000000000000000000000000000000059682f000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000642ac0df260000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000411de3d1ce0d680d92171da7852a1df1a655280126d809b6f10d046a60e257c187684da02cf3fb67e6939ac48459e26f6c0bfdedf70a1e8f6921a4a0ff331448641b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; const decodedData = abiDecoder.decodeMethod(testData); expect(decodedData).to.be.an("object"); expect(decodedData).to.have.all.keys("name", "params"); expect(decodedData.name).to.be.a("string"); expect(decodedData.params).to.be.a("array"); expect(decodedData.params).to.have.length(3); expect(decodedData.params[0].value).to.deep.equal([["0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B", "1000000", "24000000000", "0x2ac0df260000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000"], ["0x50A5cf333FC36A18c8F96B1D1e7a2B013C6267aC", "0", "0x46DCcF96Fe3f3bEEf51c72c68A1F3Ad9183a6561", "12"]]); });
it(`GET should return a tag`, function(done) { chai.request(server) .get('/v1/tags/'+DUMMY_TAG.id) .set('Authorization', global.HEADER_TOKEN) .end((err, res) => { expect(err).to.be.null; expect(res.body.tag).to.be.an('object').that.include.all.keys('id', 'name', 'postId', 'userId'); expect(res.status).to.equal(200); done(); }) });
it("should not return user data if parameters are not passed", (done) => { request(app) .post("/api/user/getUserData") .set("Authorization", tokenJWT) .expect(400) .then((res) => { expect(res.body).to.have.all.keys("message"); expect(res.body.message).to.equal('"profilePage" is required'); done(); }) .catch((err) => done(err)); });
describe('retrieving news site choices', function() { it('should return an array of objects with particular keys', async function() { const newsSiteChoices = await cli.retrieveNewsSiteChoices(); expect(newsSiteChoices).to.be.an('array'); for (const newsSiteChoice of newsSiteChoices) { expect(newsSiteChoice).to.include.all.keys('title', 'value'); } }); });
it('GET should get a menu with id', function(done) { chai.request(server) .get('/v1/menus/'+DUMMY_MENU.id) .set('Authorization', global.HEADER_TOKEN) .end((err, res) => { expect(err).to.be.null; expect(res.body.success).to.be.true; expect(res.body.menu).to.be.an('object').that.include.all.keys('id', 'name', 'linkedURL', 'linkedPage','postId'); expect(res.status).to.be.equal(200); done(); }); })
it("should not return user data if jwt is not passed", (done) => { request(app) .post("/api/user/getUserData") .send({ initialFetch: true }) .expect(401) .then((res) => { expect(res.body).to.have.all.keys("message"); expect(res.body.message).to.equal("Invalid token"); done(); }) .catch((err) => done(err)); });
it('GET should get a new page with id', function(done) { chai.request(server) .get('/v1/pages/'+DUMMY_PAGE.id) .set('Authorization', global.HEADER_TOKEN) .end((err, res) => { expect(err).to.be.null; expect(res.body.success).to.be.true; expect(res.body.page).to.be.an('object').that.include.all.keys('id', 'name', 'menuId', 'userId'); expect(res.status).to.be.equal(200); done(); }); })
it("should require lastId if initialFetch is false", (done) => { request(app) .post("/api/user/getNewUsers") .send({ initialFetch: false }) .expect(400) .then((res) => { expect(res.body).to.have.all.keys("message"); expect(res.body.message).to.equal('"lastId" is required'); done(); }) .catch((err) => done(err)); });