it('should delete an item on delete', function (done) { chai.request(app) .delete('items/1') .end(function (err, res) { should.equal(err, null); res.should.have.status(200); res.should.be.json; // res.body is the deleted object {name: '', id: #} res.body.should.be.a('object'); res.body.should.have.property('name'); res.body.should.have.property('id'); res.body.name.should.be.a('string'); res.body.id.should.be.a('number'); res.body.id.should.equal(1); res.body.name.should.equal('Tomatoes'); storage.items.length.should.equal(3); storage.items[0].name.should.equal('Broad beans'); storage.items[1].name.should.equal('Tomatoes'); storage.items[2].name.should.equal('Peppers'); done(); }); });
it('should edit an item on PUT',function(done) { chai.request(app) .put('/items/0') .send({'name':'Cheesy Poofs'}) // new data at items[0]:Cheesy Poofs .end(function(err,response) { response.should.have.status(201); response.should.be.json; response.body.should.be.a('object'); response.body.should.have.property('name'); response.body.should.have.property('id'); response.body.name.should.be.a('string'); response.body.id.should.be.a('number'); response.body.name.should.equal('Cheesy Poofs'); storage.items[0].should.be.a('object'); storage.items[0].should.have.property('id'); storage.items[0].should.have.property('name'); storage.items[0].id.should.be.a('number'); storage.items[0].name.should.be.a('string'); storage.items[0].name.should.equal('Cheesy Poofs'); done(); }); });
it('should reject duplicates', function ( done ) { chai.request(app) .post('/api/users/') .set('X-API-Token', _token) .send({ user: { name: { first: 'Test', last: 'Tester' }, login: { email: '*****@*****.**' } } }) .then(function ( res ) { expect(res).to.have.status(400); expect(res.error.text.toLowerCase()).to.contain('exists'); done(); }); });
it('should add a single show', function(done) { chai.request(server) .get('/api/shows/1') .end(function(err, res) { res.should.have.status(200); res.should.be.json; res.body[0].should.be.a('object'); res.body.length.should.equal(1); res.body[0].should.have.property('name'); res.body[0].name.should.equal('Suits'); res.body[0].should.have.property('channel'); res.body[0].channel.should.equal('USA Network'); res.body[0].should.have.property('genre'); res.body[0].genre.should.equal('Drama'); res.body[0].should.have.property('rating'); res.body[0].rating.should.equal(3); res.body[0].should.have.property('explicit'); res.body[0].explicit.should.equal(false); done(); }); });
.end(function(err, res) { if (err) { console.log(err); } chai.request(app) .put('/api/images/'+res.body[0]._id) .send({'title': 'Updated Title'}) .end(function(error, response) { if (error) { console.log(err); } response.should.have.status(200); response.should.be.json; response.body.should.be.a('object'); response.body.should.have.property('UPDATED'); response.body.UPDATED.should.be.a('object'); response.body.UPDATED.should.have.property('title'); response.body.UPDATED.should.have.property('_id'); response.body.UPDATED.title.should.equal('Updated Title'); done(); }); });
.end(function(err, res) { targetID = res.body[0]._id; chai.request(app) .get('/users/' + targetID) .end(function(err, res) { should.equal(err, null); res.should.have.status(200); res.should.be.json; res.body.should.be.a('object'); res.body.should.have.property('_id'); res.body.should.have.property('username'); res.body.should.have.property('password'); res.body.should.have.property('stocks'); res.body.stocks.should.be.a('array'); res.body.username.should.be.equal('Test User'); res.body.password.should.be.equal('password'); res.body.stocks[0].should.be.equal('AAPL'); res.body.stocks[1].should.be.equal('YHOO'); res.body.stocks[2].should.be.equal('FB'); done(); }); });
it('should be able to add SMTP info', function(done) { chai.request('http://localhost:3000') .post('/api/userSMTP') .set({jwt:jwtToken}) .send({ host: 'smtp.gmail.com', port: '465', secure: true, username: '******', password: '******' }) .end(function(err, res) { expect(err).to.eql(null); expect(res).to.have.status(202); expect(res.body).to.have.property('host'); expect(res.body).to.have.property('port'); expect(res.body).to.have.property('secure'); expect(res.body).to.have.property('username'); expect(res.body).to.have.property('password'); done(); }); });
it("responds with 409 when trying to grant the achievement again", function(done) { chai.request(app) .post('/users/' + users[1].id + '/grant/' + template1.id) .set('Cookie', helper.sessionCookies({ 'passport': { 'user': users[0].id } })) .end(function(err, res) { expect(err).to.be.null; expect(res).to.have.status(409); Achievement.find({ owner: users[1].id, template: template1.id }, function(err, achievements) { expect(err).to.be.null; expect(achievements.length).to.equal(1); expect(achievements[0].grantedBy.toString()).to.equal([users[0].id].toString()); done(); }); }); });
it('should return false if client id or secret is not set', () => { configMock = { clientId : null, clientSecret : null }; mock['../config/environment'] = configMock; let appErr = express(); let router = proxyquire('../routes/github', mock); router(appErr); appErr.listen(); return chai.request(appErr) .get('/api/isOAuthEnabled') .then((res) => { res.should.have.status(200); res.should.be.json; res.body.should.be.an('boolean'); res.body.should.be.false; }); });
it('should not update a author', function(done) { chai.request(server) .post('/authors/1/edit') .send({ first_name: 'Michael', last_name: 'Herman', biography: 'I am an author', portrait_url: 'https://me.martelli.jpg' }) .end(function(err, res) { res.should.have.status(200); res.should.be.html; // jshint ignore:line res.text.should.have.string( '<h1 class="page-header">Galvanize Reads</h1>'); queries.getAuthors() .then(function(authors) { authors[0].first_name.should.equal('Alex'); databaseHelpers.mapBooksToAuthors(authors).length.should.equal(allAuthors.length); done(); }); }); });
it('should sort the list correctly', () => { sortableList = true; return chai.request(app) .get('/api/getSampleList') .then((res) => { res.should.have.status(200); res.should.be.json; res.body.should.be.an('array'); if (testMode) { res.body.should.deep.equal([{ name : 'basic-sample-network' }]); } else { res.body.should.deep.equal([{ name : 'ant', description : 'ant package', version : '1.0', tarball : 'my tar', networkImage : 'https://hyperledger.github.io/composer-sample-networks/packages/ant/networkimage.svg', networkImageanimated : 'https://hyperledger.github.io/composer-sample-networks/packages/ant/networkimageanimated.svg', }, { name : 'bat', description : 'bat package', version : '1.0', tarball : 'my tar', networkImage : 'https://hyperledger.github.io/composer-sample-networks/packages/bat/networkimage.svg', networkImageanimated : 'https://hyperledger.github.io/composer-sample-networks/packages/bat/networkimageanimated.svg', }, { name : 'cat', description : 'cat package', version : '1.0', tarball : 'my tar', networkImage : 'https://hyperledger.github.io/composer-sample-networks/packages/cat/networkimage.svg', networkImageanimated : 'https://hyperledger.github.io/composer-sample-networks/packages/cat/networkimageanimated.svg', }]); } }); });
.end(function(err, res) { chai.request(server) .get('api/shows/' + res.body[0]) .end(function(error, res) { res.should.have.status(200); res.should.be.json; res.body.should.be.a('array'); res.body.length.should.equal(1); res.body[0].should.have.property('name'); res.body[0].name.should.equal('testing'); res.body[0].should.have.property('channel'); res.body[0].channel.should.equal('whatever'); res.body[0].should.have.property('genre'); res.body[0].genre.should.equal('great'); res.body[0].should.have.property('rating'); res.body[0].rating.should.equal(1); res.body[0].should.have.property('explicit'); res.body[0].explicit.should.equal(false); }); done(); })
it('returns all categories in flat structure', function() { return chai.request(env.openwhiskEndpoint) .get(env.categoriesPackage + 'getCategories') .query({ type: 'flat' }) .set('Accept-Language', 'en-US') .set('Cache-Control', 'no-cache') .then(function (res) { expect(res).to.be.json; expect(res).to.have.status(HttpStatus.OK); requiredFields.verifyPagedResponse(res.body); expect(res.body.count).to.equal(24); expect(res.body.results).to.have.lengthOf(24); // Verify structure for (let category of res.body.results) { requiredFields.verifyCategory(category); expect(category).to.not.have.own.property('children'); } }); });
it('returns all categories in flat structure sorted by their names', function() { return chai.request(env.openwhiskEndpoint) .get(env.categoriesPackage + 'getCategories') .query({ type: 'flat', sort: 'name.desc' }) .set('Accept-Language', 'en-US') .set('Cache-Control', 'no-cache') .then(function (res) { expect(res).to.be.json; expect(res).to.have.status(HttpStatus.OK); requiredFields.verifyPagedResponse(res.body); for (let category of res.body.results) { requiredFields.verifyCategory(category); } // Verfiy sorting const names = res.body.results.map(r => r.name.en); expect(names).to.have.ordered.members(names.sort().reverse()); }); });
it('Get specific object', function (done) { chai.request(app) .get('/name/2') .end(function (err, res) { if (err) { throw err; } res.should.have.status(200); res.should.be.json; res.body.should.have.property('id'); res.body.should.have.property('nombre'); res.body.should.have.property('apellido'); res.body.id.should.equal(2); res.body.nombre.should.equal('Pedro'); res.body.apellido.should.equal('Lopez'); done(); }); });
it('should find update a document in the entries collection', function(done) { var obj = { "_id": "55219690bb662780ede4763d", "date": "2000/01/03", "reference": "Transfer", "number": "", "payee": "", "memo": "Funds Transfer", "account": "Petty Cash", "payment": "40", "deposit": "0" } chai.request(server) .post('/chkUpdate') .send(obj) .end(function (err, res) { expect(res.status).to.equal(200) expect(res.body).to.be.an('object'); done(); }); });
it('should delete the session', function(done){ let session = { 'name': 'test1', 'timing': '2017-10-10', 'description': 'Dummy', 'grade': 'dummy', 'price': '123' }; chai.request(server) .delete('/api/session/deleteSession/' + sessionId) .send(session) .set('authorization', UserAuthorization) .end(function (err, res) { res.status.should.be.eql(200); res.should.be.json; res.body.should.have.property('msg'); res.body.msg.should.be.eql('Session was deleted successfully'); res.body.data._id.should.be.eql(sessionId); done(); }); });
.end(function (err, res) { expect(err).to.be.null; expect(res).to.have.status(404); expect(res.body.name).to.equal(undefined); chai.request(app) .delete('/api/relationship') .set('Authorization', 'Bearer i24gowinvnweajoi') .send(params) .end(function (err, res) { expect(err).to.be.null; expect(res).to.have.status(201); chai.request(app) .get('/api/users/?id=346&userInArea=348') .set('Authorization', 'Bearer i24gowinvnweajoi') .end(function (err, res) { expect(err).to.be.null; expect(res).to.have.status(200); expect(res.body.name).to.equal("Raw Dog"); done(); }); }); });
it('adds a coupon code to an existing cart', function () { const args = { id: cartId, code: 'HW35' }; return chai.request(env.openwhiskEndpoint) .post(env.cartsPackage + 'postCoupon') .query(args) .set('Accept-Language', 'en-US') .set('cookie', `${OAUTH_TOKEN_NAME}=${accessToken};`) .then(function(res) { expect(res).to.be.json; expect(res).to.have.status(HttpStatus.OK); requiredFields.verifyCart(res.body); expect(res.body).to.have.property('coupons'); expect(res.body.coupons).to.have.lengthOf(1); let coupon = res.body.coupons[0]; requiredFields.verifyCoupon(coupon); expect(coupon).to.have.property('description'); }); });
it('should reject non-string usernames', function() { var user = { username: 42 }; var spy = chai.spy(); return chai.request(app) .post(this.pattern.stringify()) .send(user) .then(spy) .then(function() { spy.should.not.have.been.called(); }) .catch(function(err) { var res = err.response; res.should.have.status(422); res.type.should.equal('application/json'); res.charset.should.equal('utf-8'); res.body.should.be.an('object'); res.body.should.have.property('message'); res.body.message.should.equal('Incorrect field type: username'); }); });
client.query('delete from profiles', (err, result) => { pgDone2(); chai.request(server) .post('/auth/signup') .send({ email: '*****@*****.**', isTeacher: true, password: '******', displayName: 'Testy', lastName: 'Mctestface', description: 'Quis aute iure reprehenderit in voluptate velit esse. Mercedem aut nummos unde unde extricat, amaras. Morbi odio eros, volutpat ut pharetra vitae, lobortis sed nibh. Ab illo tempore, ab est sed immemorabili. Gallia est omnis divisa in partes tres, quarum.', state: 'CO', avatarUrl: 'http://s3.aws.com/someimage0908234.jpg' }) .end((err, res) => { teacherToken = res.body.token; done(); }); if(err) { return console.error('error running query', err); } });
it('expect add a organizador to campeonato', function(done) { chai.request(app) .get('/V1/api/campeonato/'+ idCampeonato + '/organizador/' + user._id) .set('x-access-token', token) .end(function(err, res){ console.log(err); // console.log(res.body); expect(res.status).to.be.eq(200); expect(res.type).to.be.eq('application/json'); // expect(res.body).to.include.keys('location'); //expect(res.body).to.include.keys('data'); // expect(res.body.data).to.include.keys('email'); // expect(res.body.data).to.include.keys('password'); // expect(res.body.data).to.include.keys('_id'); // expect(res.body.data).to.include.keys('created_at'); // //testando valores // expect(res.body.data.email).to.equal('*****@*****.**'); id = res.body._id; // email = res.body.data.email; done(); }); });
it('uses the default Accept-Language when it is missing from the request', function () { const args = { id: cartId, code: 'HW35' }; return chai.request(env.openwhiskEndpoint) .post(env.cartsPackage + 'postCoupon') .query(args) .set('cookie', `${OAUTH_TOKEN_NAME}=${accessToken};`) .then(function(res) { expect(res).to.be.json; expect(res).to.have.status(HttpStatus.OK); requiredFields.verifyCart(res.body); expect(res.body).to.have.property('coupons'); expect(res.body.coupons).to.have.lengthOf(1); let coupon = res.body.coupons[0]; requiredFields.verifyCoupon(coupon); expect(coupon).to.have.property('description'); expect(coupon).to.have.property('description').equal('This is a sample description') }); });
it('should save a user to the database', (done) => { chai.request(server) .post('/api/users/create') .send({ email :'*****@*****.**', password: '******', passwordConfirmation: 'passwordPASSWORD123', userType: 'user' }) .end((err, res) => { res.should.have.status(200); res.should.be.json; res.body.should.have.property('id'); res.body.id.should.equal(3); res.body.should.have.property('email'); res.body.email.should.equal('*****@*****.**'); done(); }) });
it('should delete a SINGLE image on /images/:id DELETE', function(done) { chai.request(app) .get('/api/images') .end(function(err, res) { if (err) { console.log(err); } chai.request(app) .delete('/api/images/' + res.body[0]._id) .end(function(error, response) { response.should.have.status(204); response.should.be.json; response.body.should.be.a('object'); response.body.should.have.property('REMOVED'); response.body.REMOVED.should.be.a('object'); response.body.REMOVED.should.have.property('title'); response.body.REMOVED.should.have.property('_id'); response.body.REMOVED.name.should.equal('Great Image'); done(); }); }); });
it('should 404 on non-existent messages', function() { var spy = makeSpy(); // Get a message which doesn't exist return chai.request(app) .get(this.singlePattern.stringify({messageId: '000000000000000000000000'})) .then(spy) .catch(function(err) { // If the request fails, make sure it contains the // error var res = err.response; res.should.have.status(404); res.type.should.equal('application/json'); res.charset.should.equal('utf-8'); res.body.should.be.an('object'); res.body.should.have.property('message'); res.body.message.should.equal('Message not found'); }) .then(function() { // Check that the request didn't succeed spy.called.should.be.false; }); });
setTimeout(function() { chai.request(server) .put('/v2/service_instances/' + instanceId + '/service_bindings/' + bindingId) .set('X-Broker-API-Version', '2.8') .auth('demouser', 'demopassword') .send({ "plan_id": planId, "service_id": serviceId, "app_guid": uuid.v4(), "parameters": bindingParameters }) .end(function(err, res) { res.should.have.status(201); res.should.be.json; res.body.should.be.a('object'); res.body.should.have.property('credentials'); var actualCredentials = res.body.credentials; var keys = _.keys(credentials); _.each(keys, function(key) { res.body.credentials.should.have.property(key); var value = credentials[key]; if (_.isString(value) && value.startsWith('<') && value.endsWith('>')) { res.body.credentials.should.have.property(key).be.a(value.slice(1, -1)); } else { res.body.credentials.should.have.property(key, value); } }); client = clients[serviceName]; if(client) { client.validateCredential(actualCredentials, function(result) { result.should.equal(statusCode.PASS); done(); }); } else { console.warn("Credential not yet verified!"); done(); } }); }, 10000);
it('should return posts descending by date', function(done){ chai.request(server) .post('/all') .send({ order: 'descending', compare: 'createdAt' }) .end(function(err, res){ expect(err).to.equal(null); var data = JSON.parse(res.text); var sorted = data.reduce(function(a,b){ var dateA = new Date(a.createdAt); var dateB = new Date(b.createdAt); if(dateA < dateB){ return false; } return b; }) expect(sorted).to.not.equal(false); done(); }) });
it('should create a new student', function(done) { chai.request(server) .post('/students') .send({ firstName: 'Michael', lastName: 'Johnson', year: 9999 }) .end(function(err, res) { res.status.should.equal(200); res.type.should.equal('application/json'); res.body.should.be.a('object'); res.body.should.have.property('status'); res.body.should.have.property('data'); res.body.status.should.equal('success'); res.body.data.should.be.a('object'); res.body.data.firstName.should.equal('Michael'); res.body.data.lastName.should.equal('Johnson'); res.body.data.year.should.equal(9999); done(); }); });
it('should create multiple files', function ( done ) { chai.request(app) .post('/client-api/files/') .set('X-API-Token', _auth.publicKey) .attach(_testFiles[0], _testFilePaths[0]) .attach(_testFiles[1], _testFilePaths[1]) .then(function ( res ) { expect(res).to.have.status(201); File.find({ _id: { $in: _.map(res.body.file, '_id') } }, function ( err, file ) { if ( err ) throw err; expect(file).to.have.length(2); file.forEach(function ( f ) { expect(fs.existsSync(f.location), 'File Exists').to.equal(true); }); done(); }); }); });