From 9f60fcc8659d234c25b410ffb6338bd41ee1f4bd Mon Sep 17 00:00:00 2001 From: Anton Synenko Date: Tue, 13 Aug 2019 11:32:47 +0300 Subject: [PATCH] remove all future or outdated banners in contentful_banners_spec test after readFileMaybe --- cypress/integration/contentful_banners_spec.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cypress/integration/contentful_banners_spec.js b/cypress/integration/contentful_banners_spec.js index 07f1cb2dc4..07b9d6f417 100644 --- a/cypress/integration/contentful_banners_spec.js +++ b/cypress/integration/contentful_banners_spec.js @@ -9,7 +9,18 @@ describe('Contentful driven banners', () => { .then((yamlString) => { if (typeof yamlString === 'undefined' || yamlString === null) return this.skip() - return YAML.parse(yamlString) + const yamlObject = YAML.parse(yamlString) + + // remove all outdated or future banners + const setMyTimezoneToDate = (date) => new Date(Date.parse(date)) + + return yamlObject.filter((banner) => { + const now = new Date() + const startDate = setMyTimezoneToDate(banner.startDate) + const endDate = setMyTimezoneToDate(banner.endDate) + + return startDate <= now && now <= endDate + }) }) .then((banners) => { if (typeof banners === 'undefined' || !banners || !banners.length) return this.skip()