Skip to content

Commit

Permalink
chore: e2e tests for 500 error
Browse files Browse the repository at this point in the history
  • Loading branch information
nightnei committed Apr 19, 2021
1 parent 66b0652 commit 8fcaf18
Show file tree
Hide file tree
Showing 11 changed files with 467 additions and 12 deletions.
1 change: 1 addition & 0 deletions e2e/codecept.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ exports.config = {
newsPage: path.join(__dirname, 'spec', 'pages', 'news.ts'),
planetsPage: path.join(__dirname, 'spec', 'pages', 'planets.ts'),
hooksPage: path.join(__dirname, 'spec', 'pages', 'hooks.ts'),
common: path.join(__dirname, 'spec', 'pages', 'common.ts'),
},
tests: './spec/**/*.spec.e2e.ts',
name: 'ilc',
Expand Down
39 changes: 39 additions & 0 deletions e2e/spec/500.spec.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Feature('500 error handling');

//region 500 page
Scenario('Renders 500 page', (I, common: common) => {
I.amOnPage(common.url.urlInternalServerError);
I.seeInSource(common.textError500);
I.seeInSource(common.textErrorId);
I.dontSeeInSource(common.textError500ForLocalhostAsIPv4);
I.seeInCurrentUrl(common.url.urlInternalServerError);
});
Scenario('should open 500 error page when an error happens', async (I, newsPage: newsPage, common: common) => {
I.amOnPage(newsPage.url.main);
I.waitInUrl(newsPage.url.main, 10);
I.waitForElement(newsPage.generateError, 10);
I.click(newsPage.generateError);
I.seeInSource(common.textError500);
I.seeInSource(common.textErrorId);
I.dontSeeInSource(common.textError500ForLocalhostAsIPv4);
I.seeInCurrentUrl(newsPage.url.main);
});

Scenario('Renders 500 page for domain 127.0.0.1', (I, common: common) => {
I.amOnPage(common.url.localhostAsIPv4 + common.url.urlInternalServerError);
I.seeInSource(common.textError500ForLocalhostAsIPv4);
I.seeInSource(common.textErrorId);
I.dontSeeInSource(common.textError500);
I.seeInCurrentUrl(common.url.localhostAsIPv4 + common.url.urlInternalServerError);
});
Scenario('should open 500 error page when an error happens for domain 127.0.0.1', async (I, newsPage: newsPage, common: common) => {
I.amOnPage(common.url.localhostAsIPv4 + newsPage.url.main);
I.waitInUrl(newsPage.url.main, 10);
I.waitForElement(newsPage.generateError, 10);
I.click(newsPage.generateError);
I.seeInSource(common.textError500ForLocalhostAsIPv4);
I.seeInSource(common.textErrorId);
I.dontSeeInSource(common.textError500);
I.seeInCurrentUrl(common.url.localhostAsIPv4 + newsPage.url.main);
});
//endregion 500 page
9 changes: 0 additions & 9 deletions e2e/spec/news.spec.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,3 @@ Scenario('should open an article page from a direct link', async (I, newsPage: n
I.seeInCurrentUrl(lastNewsSourceLinkHref);
I.closeOtherTabs();
});

Scenario('should open 500 error page when an error happens', async (I, newsPage: newsPage) => {
I.amOnPage(newsPage.url.main);
I.waitInUrl(newsPage.url.main, 10);
I.waitForElement(newsPage.generateError, 10);
I.click(newsPage.generateError);
I.waitForElement(newsPage.errorId);
I.seeInCurrentUrl(newsPage.url.main);
});
8 changes: 8 additions & 0 deletions e2e/spec/pages/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const url = {
urlInternalServerError: '/_ilc/500',
localhostAsIPv4: 'http://127.0.0.1:8233',
};

export const textError500 = '<h3>ERROR 500</h3>';
export const textError500ForLocalhostAsIPv4 = '<h3>500 Internal Server Error on 127.0.0.1</h3>';
export const textErrorId = 'Error ID:';
1 change: 0 additions & 1 deletion e2e/spec/pages/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const newsView = 'body > div#body > div.single-spa-container.news-app > d
export const newsSources = `${newsView} > div.sources > div.container > ol > li.source`;
export const bannerHeadline = `${newsView} > div.banner > h1`;
export const generateError = `${newsView} > div.banner > a`;
export const errorId = `body > div#error > p:nth-child(3)`;
export const lastNewsSource = `${newsSources}:last-child`;
export const lastNewsSourceLink = `${lastNewsSource} > p.action > a`;
export const newsSourceArticles = `${newsView} > div.container > div.articles > ol > li.article`;
Expand Down
5 changes: 3 additions & 2 deletions e2e/typings/steps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ type peoplePage = typeof import('../spec/pages/people');
type newsPage = typeof import('../spec/pages/news');
type planetsPage = typeof import('../spec/pages/planets');
type hooksPage = typeof import('../spec/pages/hooks');
type common = typeof import('../spec/pages/common');
type MockRequestHelper = import('@codeceptjs/mock-request');

declare namespace CodeceptJS {
interface SupportObject { I: CodeceptJS.I, peoplePage: peoplePage, newsPage: newsPage, planetsPage: planetsPage, hooksPage: hooksPage }
interface CallbackOrder { [0]: CodeceptJS.I; [1]: peoplePage; [2]: newsPage; [3]: planetsPage; [4]: hooksPage }
interface SupportObject { I: CodeceptJS.I, peoplePage: peoplePage, newsPage: newsPage, planetsPage: planetsPage, hooksPage: hooksPage, common: common }
interface CallbackOrder { [0]: CodeceptJS.I; [1]: peoplePage; [2]: newsPage; [3]: planetsPage; [4]: hooksPage; [5]: common }
interface Methods extends CodeceptJS.Puppeteer, MockRequestHelper {}
interface I extends WithTranslation<Methods> {}
namespace Translation {
Expand Down
2 changes: 2 additions & 0 deletions ilc/server/errorHandler/ErrorHandler.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('ErrorHandler', () => {
});

it('should show 500 error page with an error id', async () => {
nock(config.get('registry').address).get('/api/v1/router_domains').reply(200, []);
nock(config.get('registry').address).get(`/api/v1/template/500/rendered`).reply(200, {
content:
'<html>' +
Expand Down Expand Up @@ -59,6 +60,7 @@ describe('ErrorHandler', () => {
});

it('should send an error message when showing 500 error page throws an error', async () => {
nock(config.get('registry').address).get('/api/v1/router_domains').reply(200, []);
const replyingError = new Error('Something awful happened.');

nock(config.get('registry').address).get(`/api/v1/template/500/rendered`).replyWithError(replyingError.message);
Expand Down
1 change: 1 addition & 0 deletions registry/server/seeds/00_cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export async function seed(knex: Knex): Promise<any> {
await knex('apps').transacting(trx).truncate();
await knex('templates').transacting(trx).truncate();
await knex('shared_props').transacting(trx).truncate();
await knex('router_domains').transacting(trx).truncate();
} finally {
isMySQL(knex) && await knex.schema.raw('SET FOREIGN_KEY_CHECKS = 1;').transacting(trx);
}
Expand Down
6 changes: 6 additions & 0 deletions registry/server/seeds/02_templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ export async function seed(knex: Knex): Promise<any> {
encoding: 'utf8',
})
},
{
name: '500ForLocalhostAsIPv4',
content: fs.readFileSync(path.join(__dirname, './data/templates/500ForLocalhostAsIPv4.html'), {
encoding: 'utf8',
})
},
]);
}
11 changes: 11 additions & 0 deletions registry/server/seeds/06_routerDomains.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Knex from 'knex';

export async function seed(knex: Knex): Promise<any> {
return knex("router_domains").insert([
{
id: 1,
domainName: '127.0.0.1:8233',
template500: '500ForLocalhostAsIPv4',
},
]);
}
Loading

0 comments on commit 8fcaf18

Please sign in to comment.