it('should handle insert error', async () => { const expectedResult = 'Invalid team specified'; await request(server) .post('/') .expect(400) .expect((response) => { assert.ok(response.text.includes(expectedResult)); }); });
it('should display the default page', async () => { await request(server) .get('/') .expect(200) .expect((response) => { assert.ok(response.text.includes('Tabs VS Spaces')); }); });
.end(function (err, res) { if (err) return t.fail(err) t.equal(res.text, 'Hello World\n', 'should respond to https request') ngrok.kill() hostile.remove('127.0.0.1', host)
describe('i18n-ja', function() { it('Japanese localized page should contain specific text when GET /', () => request(app) .get('/') .set('Accept-language', 'ja') .expect(200) .expect(function containsString(res) { if (res.text.indexOf('実際に試してみましょう!') == -1) throw new Error('Invalid translation string'); }) ); });
it('/opensearch.xml', function (done) { fs.readFile(path.join(__dirname, '../view/opensearch.xml'), {encoding: 'utf-8'}, (err, data) => { if (err) return done(err) supertest(schsrch) .get('/opensearch.xml') .expect(200) .expect('Content-Type', /opensearchdescription\+xml/) .expect(res => res.text.should.equal(data)) .end(done) }) })
describe('test/app.test.js', function() { it('should / status 200', function(done) { request(app) .get('/') .end(function(err, res) { res.status.should.equal(200) res.text.should.containEql(config.description) done() }) }) })
it('/search/?as=page', function (done) { const tQuery = `whateverqueryhere${Math.random()}` supertest(schsrch) .get('/search/?as=page&query=' + encodeURIComponent(tQuery)) .expect(200) .expect('Content-Type', /html/) .expect(res => res.text.indexOf(`<input type="text" class="querybox border" value=${JSON.stringify(tQuery)} name="query" autocomplete="off"`).should.be.aboveOrEqual(0)) .end(done) })
it('should not accept empty test', function (done) { supertest(schsrch) .post('/feedback/') .set('Content-Type', 'application/json') .send({email: '', text: '', search: null}) .expect(403) .expect(res => res.text.should.match(/content/i)) .expect(res => res.text.should.match(/required/i)) .end(done) })
it('should throw an error if requested an invalid version', function(done) { request(server) .get('/todo') .set('Accept-Version', '^3.0') .end(function(err, res) { expect(res.statusCode).to.equal(400); expect(res.text).to.equal('Version ^3.0 is not supported'); done(); }); });
it('helloHttp: should print a name', async () => { await supertest .post('/helloHttp') .send({name: 'John'}) .expect(200) .expect(response => { assert.strictEqual(response.text, 'Hello John!'); }); });
it('should not accept too long', function (done) { supertest(schsrch) .post('/feedback/') .set('Content-Type', 'application/json') .send({email: '', text: 'x'.repeat(5001), search: null}) .expect(403) .expect(res => res.text.should.match(/more than/i)) .end(done) })
describe('i18n-es', function() { it('Spanish localized page should contain specific text when GET /', () => request(app) .get('/') .set('Accept-language', 'es') .expect(200) .expect(function containsString(res) { if (res.text.indexOf('Pruebe el servicio') == -1) throw new Error('Invalid translation string'); }) ); });
describe('i18n-ko', function() { it('Korean localized page should contain specific text when GET /', () => request(app) .get('/') .set('Accept-language', 'ko') .expect(200) .expect(function containsString(res) { if (res.text.indexOf('서비스를 시도해 보십시오.') == -1) throw new Error('Invalid translation string'); }) ); });
it('should not accept too long email', function (done) { supertest(schsrch) .post('/feedback/') .set('Content-Type', 'application/json') .send({email: 'm'.repeat(5000) + '@maowtm.org', text: 'stub!', search: null}) .expect(403) .expect(res => res.text.should.match(/email/i)) .end(done) })
it('should display the default page', async () => { await request(server) .get('/') .expect(200) .expect(response => { assert.ok(response.text.includes('Tabs VS Spaces')); }); });