describe('API /', () => { it('it should return Welcome message', (done) => { chai.request(app) .get('/') .end((err, res) => { res.should.have.status(200); res.should.to.be.html; res.text.should.be.equal("Hello Docker World\n"); done(); }); }); });
it('has the correct page title', done => { test().end((err, res) => { expect(res).to.be.html; titleCheck(res, `${data.name} (${data.id}) - ${locale('site_name')} - ${locale('short_desc')}`); done(); }); });
const authCheck = res => { expect(res).to.be.html; expect(res.text).to.include('This page requires authentication to access'); expect(res.text).to.include(`Sign in to ${locale('site_name')}`); expect(res.text).to.include('A 403 error has occurred... :('); }
describe('GET Invalid (:id = helloworld)', () => { const test = () => request().get('/lists/helloworld'); it('returns a Not Found status code', done => { test().end((err, res) => { expect(res).to.have.status(404); done(); }); }); it('renders the error content', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include('The page you were looking for could not be found.'); expect(res.text).to.include('A 404 error has occurred... :('); done(); }); }); });
describe('GET Legacy ID', () => { let id, target, data; before('fetch list data', done => { db.select().from('legacy_ids').limit(1).then(legacy => { id = legacy[0].id; target = legacy[0].target; db.select().from('lists').where({ id: target }).limit(1).then(lists => { data = lists[0]; done(); }); }); }); it('returns the target list page', done => { const test = () => request().get(`/lists/${id}`); test().end((err, res) => { expect(res).to.have.status(200); expect(res).to.be.html; titleCheck(res, `${data.name} (${data.id}) - ${locale('site_name')} - ${locale('short_desc')}`); done(); }); }); });
it('renders the list API information', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include('<b class="has-text-grey-lighter">List API information:</b>'); expect(res.text).to.include('<b class="has-text-grey-lighter">This list has an API endpoint for posting server/guild count of a bot:</b>'); expect(res.text).to.include('https://api.botlist.space/v1/bots/:id'); // TODO: Use DB expect(res.text).to.include('<b class="has-text-grey-lighter">This list\'s API provides the following shard support for server/guild count posting:</b>'); expect(res.text).to.include('<b class="has-text-grey-lighter">BotBlock server/guild count API:</b>'); expect(res.text).to.include('Provide your botlist.space API authorisation token as the value for the key'); // TODO: Use DB expect(res.text).to.include('<code>botlist.space</code> in your server/guild count API request'); // TODO: Use DB expect(res.text).to.include('<b class="has-text-grey-lighter">This list also has an API endpoint for getting information about a bot:</b>'); expect(res.text).to.include('https://api.botlist.space/v1/bots/:id'); // TODO: Use DB done(); }); });
describe('/helloworld', () => { describe('GET', () => { const test = () => request().get('/helloworld'); it('returns a Not Found status code', done => { test().end((err, res) => { expect(res).to.have.status(404); done(); }); }); it('has the correct page title', done => { test().end((err, res) => { expect(res).to.be.html; titleCheck(res, `Page not found - ${locale('site_name')} - ${locale('short_desc')}`); done(); }); }); it('renders the error content', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include('The page you were looking for could not be found.'); expect(res.text).to.include('A 404 error has occurred... :('); done(); }); }); }); });
const titleCheck = (res, expectedTitle) => { expect(res).to.be.html; // Generic expect(res.text).to.include(`<title>${expectedTitle}</title>`); expect(res.text).to.include(`<meta name="description" content="${locale('site_name')} - ${locale('full_desc')}">`); // OG expect(res.text).to.include(`<meta property="og:title" content="${expectedTitle}">`); expect(res.text).to.include(`<meta property="og:site_name" content="${locale('site_name')}">`); expect(res.text).to.include(`<meta property="og:description" content="${locale('full_desc')}">`); // Twitter expect(res.text).to.include(`<meta name="twitter:title" content="${expectedTitle}">`); expect(res.text).to.include(`<meta name="twitter:description" content="${locale('full_desc')}">`); }
it('provides the basic list information', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include(`<p class="title is-3">${data.name}</p>`); expect(res.text).to.include(`<p class="subtitle is-6">${data.url}${data.description ? `<br><br>${data.description}` : ''}</p>`); done(); }); });
it('renders the expected header content', done => { test().end((err, res) => { expect(res).to.be.html; // Confirm header expect(res.text).to.include('API Documentation'); expect(res.text).to.include(`${locale('site_name')} provides a single API endpoint`); // Confirm CTA to libs expect(res.text).to.include('<a class="button is-brand is-size-5" href="/api/docs/libs">API Libraries</a>'); // Confirm menu expect(res.text).to.include('<aside class="menu">'); expect(res.text).to.include('<p class="menu-label">'); expect(res.text).to.include('<ul class="menu-list">'); done(); }); });
it('has the correct page title', done => { test().end((err, res) => { expect(res).to.be.html; titleCheck(res, `API Docs - ${locale('site_name')} - ${locale('short_desc')}`); done(); }); });
it('renders the list features', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include('<b class="has-text-grey-lighter">List features:</b>'); expect(res.text).to.include('<div class="column is-full-mobile left">'); expect(res.text).to.include('<div class="checkbox always'); expect(res.text).to.include('<div class="checkbox-inner tooltip" data-tooltip="'); expect(res.text).to.include('<a class="button is-light is-small" id="feature_toggle" data-toggled="0">Show All</a>'); done(); }); });
it('provides the list language', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include(`<b class="has-text-primary">Primary Language:</b><br>${data.language}`); done(); }); });
it('renders the additional known URLs', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include('<b>Additional known URLs for this bot list:</b>'); expect(res.text).to.include('https://botlist.space/bot/:id'); // TODO: Use DB expect(res.text).to.include('https://botlist.space/bot/:id/widget'); // TODO: Use DB done(); }); });
it('provides the list owners', done => { test().end((err, res) => { expect(res).to.be.html; expect(res.text).to.include(`<b class="has-text-primary">Owners:</b><br>${data.owners}`); done(); }); });