From 16d3fe19ef5c4248ff6004ae74ec42149f5d411a Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Tue, 5 Jun 2018 15:24:15 +0100 Subject: [PATCH 01/13] Statically serve files in /data --- src/server/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/index.js b/src/server/index.js index f23bb612c68..4ee1f3f4eb0 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,6 +9,7 @@ const assets = require(process.env.RAZZLE_ASSETS_MANIFEST); const server = express(); server .disable('x-powered-by') + .use("/data", express.static('data')) .use(express.static(process.env.RAZZLE_PUBLIC_DIR)) .get('/status', (req, res) => { res.sendStatus(200); From 3738e69f68724ad63dda6adce177df2e8758e038 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Tue, 5 Jun 2018 15:29:48 +0100 Subject: [PATCH 02/13] Use single-quotes --- src/server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/index.js b/src/server/index.js index 4ee1f3f4eb0..03aa7ee051c 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,7 +9,7 @@ const assets = require(process.env.RAZZLE_ASSETS_MANIFEST); const server = express(); server .disable('x-powered-by') - .use("/data", express.static('data')) + .use('/data', express.static('data')) .use(express.static(process.env.RAZZLE_PUBLIC_DIR)) .get('/status', (req, res) => { res.sendStatus(200); From 86956a1ef31936bf4df59ba124d2fb6324efe1db Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Tue, 5 Jun 2018 15:24:15 +0100 Subject: [PATCH 03/13] Statically serve files in /data --- src/server/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/index.js b/src/server/index.js index f23bb612c68..4ee1f3f4eb0 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,6 +9,7 @@ const assets = require(process.env.RAZZLE_ASSETS_MANIFEST); const server = express(); server .disable('x-powered-by') + .use("/data", express.static('data')) .use(express.static(process.env.RAZZLE_PUBLIC_DIR)) .get('/status', (req, res) => { res.sendStatus(200); From 2a4acc1225558760097175dd825ee3878b7f0d36 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Tue, 5 Jun 2018 15:29:48 +0100 Subject: [PATCH 04/13] Use single-quotes --- src/server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/index.js b/src/server/index.js index 4ee1f3f4eb0..03aa7ee051c 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -9,7 +9,7 @@ const assets = require(process.env.RAZZLE_ASSETS_MANIFEST); const server = express(); server .disable('x-powered-by') - .use("/data", express.static('data')) + .use('/data', express.static('data')) .use(express.static(process.env.RAZZLE_PUBLIC_DIR)) .get('/status', (req, res) => { res.sendStatus(200); From 5fb9514ed0c08d5582fcbd72c3effa8283d5d662 Mon Sep 17 00:00:00 2001 From: Paul Chinkwende Date: Tue, 5 Jun 2018 17:49:21 +0100 Subject: [PATCH 05/13] add tests for article data pages --- cypress/integration/data_spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 cypress/integration/data_spec.js diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js new file mode 100644 index 00000000000..928b922361d --- /dev/null +++ b/cypress/integration/data_spec.js @@ -0,0 +1,15 @@ +describe('Static Articles data', () => { + + it('should display 200/OK', () => { + cy.request('/data/scenario-01.json').then(({ status }) => { + expect(status).to.eq(200) + + }) +}) + + it('should output valid JSON', () => { + cy.request('/data/scenario-01.json').then(({ body}) => { + expect(body).to.be.an("object") + }) + }) +}) From b8685aac7c504a0612a980e893c866ec7e0e25a0 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 09:41:24 +0100 Subject: [PATCH 06/13] Tidy --- cypress/integration/data_spec.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 928b922361d..ee0676742ae 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -1,15 +1,13 @@ describe('Static Articles data', () => { - it('should display 200/OK', () => { cy.request('/data/scenario-01.json').then(({ status }) => { - expect(status).to.eq(200) - - }) -}) + expect(status).to.eq(200); + }); + }); it('should output valid JSON', () => { - cy.request('/data/scenario-01.json').then(({ body}) => { - expect(body).to.be.an("object") - }) - }) -}) + cy.request('/data/scenario-01.json').then(({ body }) => { + expect(body).to.be.an('object'); + }); + }); +}); From 4aa1cd3eee30fd5630ac6c5e2b9cb2f6151feb20 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 09:49:23 +0100 Subject: [PATCH 07/13] Wrap body tests in describe block --- cypress/integration/data_spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index ee0676742ae..159810ad687 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -5,9 +5,11 @@ describe('Static Articles data', () => { }); }); - it('should output valid JSON', () => { - cy.request('/data/scenario-01.json').then(({ body }) => { - expect(body).to.be.an('object'); + describe('Response Body', () => { + it('should be an object', () => { + cy.request('/data/scenario-01.json').then(({ body }) => { + expect(body).to.be.an('object'); + }); }); }); }); From 63d384a09d1cd29a336f478f50e254ed357ad0ab Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 09:50:25 +0100 Subject: [PATCH 08/13] Tidy status code test --- cypress/integration/data_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 159810ad687..0a13d162f6a 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -1,5 +1,5 @@ describe('Static Articles data', () => { - it('should display 200/OK', () => { + it('should return a status code of 200', () => { cy.request('/data/scenario-01.json').then(({ status }) => { expect(status).to.eq(200); }); From dc42d3d6bfb369ed8e018b329fe36023c3798587 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 09:51:59 +0100 Subject: [PATCH 09/13] Add test for checking existance of blocks --- cypress/integration/data_spec.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 0a13d162f6a..2818f513244 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -11,5 +11,11 @@ describe('Static Articles data', () => { expect(body).to.be.an('object'); }); }); + + it('should contain a blocks object', () => { + cy.request('/data/scenario-01.json').then(({ body }) => { + expect(body).to.have.property('blocks'); + }); + }); }); }); From 7573e71feeb3bd2a3f428956a1b9412bf28e535c Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 10:58:40 +0100 Subject: [PATCH 10/13] Extract duplicated code --- cypress/integration/data_spec.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 2818f513244..4b2df153b8a 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -1,21 +1,25 @@ describe('Static Articles data', () => { - it('should return a status code of 200', () => { - cy.request('/data/scenario-01.json').then(({ status }) => { - expect(status).to.eq(200); + const testScenarioRequest = (testTitle, scenarioNumber, testAssertion) => { + it(testTitle, () => { + cy.request(`/data/scenario-${scenarioNumber}.json`).then(testAssertion); }); - }); + }; + + testScenarioRequest( + 'should return a status code of 200', + '01', + ({ status }) => { + expect(status).to.eq(200); + }, + ); describe('Response Body', () => { - it('should be an object', () => { - cy.request('/data/scenario-01.json').then(({ body }) => { - expect(body).to.be.an('object'); - }); + testScenarioRequest('should be an object', '01', ({ body }) => { + expect(body).to.be.an('object'); }); - it('should contain a blocks object', () => { - cy.request('/data/scenario-01.json').then(({ body }) => { - expect(body).to.have.property('blocks'); - }); + testScenarioRequest('should contain a blocks object', '01', ({ body }) => { + expect(body).to.have.property('blocks'); }); }); }); From 68348615de5d36b58d890a23eee13e38f266e793 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 10:59:27 +0100 Subject: [PATCH 11/13] Tidy status code title --- cypress/integration/data_spec.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 4b2df153b8a..0e530c2d531 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -5,13 +5,9 @@ describe('Static Articles data', () => { }); }; - testScenarioRequest( - 'should return a status code of 200', - '01', - ({ status }) => { - expect(status).to.eq(200); - }, - ); + testScenarioRequest('should return a 200 status code', '01', ({ status }) => { + expect(status).to.eq(200); + }); describe('Response Body', () => { testScenarioRequest('should be an object', '01', ({ body }) => { From b4bae7b2f41781af191a39e1a7f7621b7e1845fd Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 12:37:13 +0100 Subject: [PATCH 12/13] Remove dynamic scenario number --- cypress/integration/data_spec.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 0e530c2d531..81fc0be9aac 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -1,20 +1,20 @@ describe('Static Articles data', () => { - const testScenarioRequest = (testTitle, scenarioNumber, testAssertion) => { + const testScenarioRequest = (testTitle, testAssertion) => { it(testTitle, () => { - cy.request(`/data/scenario-${scenarioNumber}.json`).then(testAssertion); + cy.request(`/data/scenario-01.json`).then(testAssertion); }); }; - testScenarioRequest('should return a 200 status code', '01', ({ status }) => { + testScenarioRequest('should return a 200 status code', ({ status }) => { expect(status).to.eq(200); }); describe('Response Body', () => { - testScenarioRequest('should be an object', '01', ({ body }) => { + testScenarioRequest('should be an object', ({ body }) => { expect(body).to.be.an('object'); }); - testScenarioRequest('should contain a blocks object', '01', ({ body }) => { + testScenarioRequest('should contain a blocks object', ({ body }) => { expect(body).to.have.property('blocks'); }); }); From 42813c2a30af6205dde1232278dae49e031bf854 Mon Sep 17 00:00:00 2001 From: Jordan Tart Date: Wed, 6 Jun 2018 13:02:32 +0100 Subject: [PATCH 13/13] Refactor to request data in beforeEach step --- cypress/integration/data_spec.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cypress/integration/data_spec.js b/cypress/integration/data_spec.js index 81fc0be9aac..71790498fe0 100644 --- a/cypress/integration/data_spec.js +++ b/cypress/integration/data_spec.js @@ -1,21 +1,31 @@ describe('Static Articles data', () => { - const testScenarioRequest = (testTitle, testAssertion) => { - it(testTitle, () => { - cy.request(`/data/scenario-01.json`).then(testAssertion); + let responseStatus; + let responseBody; + + const testScenarioResponse = (title, assertion) => { + it(title, () => { + assertion(); }); }; - testScenarioRequest('should return a 200 status code', ({ status }) => { - expect(status).to.eq(200); + beforeEach(() => { + cy.request(`/data/scenario-01.json`).then(({ status, body }) => { + responseStatus = status; + responseBody = body; + }); + }); + + testScenarioResponse('should return a 200 status code', () => { + expect(responseStatus).to.eq(200); }); describe('Response Body', () => { - testScenarioRequest('should be an object', ({ body }) => { - expect(body).to.be.an('object'); + testScenarioResponse('should be an object', () => { + expect(responseBody).to.be.an('object'); }); - testScenarioRequest('should contain a blocks object', ({ body }) => { - expect(body).to.have.property('blocks'); + testScenarioResponse('should contain a blocks object', () => { + expect(responseBody).to.have.property('blocks'); }); }); });