From b3b1a3ae00ac6602cb75ab9faa3a2d216a773348 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sat, 7 Dec 2019 17:56:07 +1030 Subject: [PATCH] Added pages spec --- test/specs/pages.js | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 test/specs/pages.js diff --git a/test/specs/pages.js b/test/specs/pages.js new file mode 100644 index 0000000..fced2b2 --- /dev/null +++ b/test/specs/pages.js @@ -0,0 +1,101 @@ +import{ serial as test }from'ava'; +const { + runBefore, + g +} = require('../helper'); + +test.before(async () => { + await runBefore(); +}); + +let insertedPageId; + +test('[Success] Create a new page', async t => { + // Login + await g.request + .post('/admin/login_action') + .send({ + email: g.users[0].userEmail, + password: 'test' + }); + // Add page + const res = await g.request + .post('/admin/settings/page') + .send({ + pageName: 'This is a page name', + pageSlug: 'the-page-slug', + pageEnabled: true, + pageContent: 'This is the content of the page.' + }); + + // Keep the ID + insertedPageId = res.body.pageId; + t.deepEqual(res.body.message, 'New page successfully created'); +}); + +test('[Success] Update a page', async t => { + // Login + await g.request + .post('/admin/login_action') + .send({ + email: g.users[0].userEmail, + password: 'test' + }); + + const updatedPage = { + pageId: insertedPageId, + pageName: 'This is a new page name', + pageSlug: 'the-page-slug-has-been-changed', + pageEnabled: false, + pageContent: 'This is the new content of the page.' + }; + // Update page + const res = await g.request + .post('/admin/settings/page') + .send(updatedPage); + + t.deepEqual(res.body.message, 'Page updated successfully'); + t.deepEqual(res.body.pageId, insertedPageId); + t.deepEqual(res.body.page.pageName, updatedPage.pageName); + t.deepEqual(res.body.page.pageSlug, updatedPage.pageSlug); + t.deepEqual(res.body.page.pageEnabled, updatedPage.pageEnabled); + t.deepEqual(res.body.page.pageContent, updatedPage.pageContent); +}); + +test('[Success] Delete a page', async t => { + // Login + await g.request + .post('/admin/login_action') + .send({ + email: g.users[0].userEmail, + password: 'test' + }); + + // Update page + const res = await g.request + .post('/admin/settings/page/delete') + .send({ + pageId: insertedPageId + }); + + t.deepEqual(res.body.message, 'Page successfully deleted'); +}); + +test('[Fail] Delete an bogus page id', async t => { + // Login + await g.request + .post('/admin/login_action') + .send({ + email: g.users[0].userEmail, + password: 'test' + }); + + // Update page + const res = await g.request + .post('/admin/settings/page/delete') + .send({ + pageId: insertedPageId + }); + + t.deepEqual(res.body.message, 'Page not found'); +});