Skip to content

Commit 2587e26

Browse files
author
Matt Mazzola
committed
Add Not Found handlers to Mock App
1 parent d8d7745 commit 2587e26

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎test/test.spec.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,63 @@ describe('Protocol', function () {
449449
});
450450

451451
describe('HPM-to-MockApp', function () {
452+
describe('notfound', function () {
453+
it('GET request to uknown url returns 404 Not Found', function (done) {
454+
iframeLoaded
455+
.then(() => {
456+
hpm.get<any>('route/that/does/not/exist')
457+
.catch(response => {
458+
expect(response.statusCode).toEqual(404);
459+
done();
460+
});
461+
});
462+
});
463+
464+
it('POST request to uknown url returns 404 Not Found', function (done) {
465+
iframeLoaded
466+
.then(() => {
467+
hpm.post<any>('route/that/does/not/exist', null)
468+
.catch(response => {
469+
expect(response.statusCode).toEqual(404);
470+
done();
471+
});
472+
});
473+
});
474+
475+
it('PUT request to uknown url returns 404 Not Found', function (done) {
476+
iframeLoaded
477+
.then(() => {
478+
hpm.put<any>('route/that/does/not/exist', null)
479+
.catch(response => {
480+
expect(response.statusCode).toEqual(404);
481+
done();
482+
});
483+
});
484+
});
485+
486+
it('PATCH request to uknown url returns 404 Not Found', function (done) {
487+
iframeLoaded
488+
.then(() => {
489+
hpm.patch<any>('route/that/does/not/exist', null)
490+
.catch(response => {
491+
expect(response.statusCode).toEqual(404);
492+
done();
493+
});
494+
});
495+
});
496+
497+
it('DELETE request to uknown url returns 404 Not Found', function (done) {
498+
iframeLoaded
499+
.then(() => {
500+
hpm.delete<any>('route/that/does/not/exist')
501+
.catch(response => {
502+
expect(response.statusCode).toEqual(404);
503+
done();
504+
});
505+
});
506+
});
507+
});
508+
452509
describe('load', function () {
453510
it('POST /report/load returns 400 if the request is invalid', function (done) {
454511
// Arrange

‎test/utility/mockReportEmbed.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ export function setupMockApp(iframeContentWindow: Window, parentWindow: Window,
2424
const router = new Router.Router(wpmp);
2525
const app = mockApp;
2626

27+
/**
28+
* Setup not found handlers.
29+
*/
30+
function notFoundHandler(req, res) {
31+
res.send(404, `Not Found. Url: ${req.params.notfound} was not found.`);
32+
};
33+
router.get('*notfound', notFoundHandler);
34+
router.post('*notfound', notFoundHandler);
35+
router.patch('*notfound', notFoundHandler);
36+
router.put('*notfound', notFoundHandler);
37+
router.delete('*notfound', notFoundHandler);
38+
2739
/**
2840
* Phase 1
2941
*/

0 commit comments

Comments
 (0)