jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/398254 )
Change subject: Automatically end announcements after configured endTime
......................................................................
Automatically end announcements after configured endTime
No need to still serve any announcements after they ended.
Probably should look into making the spec.yaml entry optional.
Change-Id: Id27816938108f82f09f522702dede79d630b630a
---
M lib/feed/announcements.js
M spec.yaml
M test/lib/feed/announcements.js
3 files changed, 50 insertions(+), 18 deletions(-)
Approvals:
jenkins-bot: Verified
Mholloway: Looks good to me, approved
diff --git a/lib/feed/announcements.js b/lib/feed/announcements.js
index 08fb116..5e3a956 100644
--- a/lib/feed/announcements.js
+++ b/lib/feed/announcements.js
@@ -82,10 +82,23 @@
return domain === 'en.wikipedia.beta.wmflabs.org';
}
+function hasEnded(now) {
+ const endDate = Date.parse(config.endTime);
+ if (isNaN(endDate)) {
+ return true; // end right away if config.endTime is invalid
+ }
+ return now > endDate;
+}
+
+function isActive(domain, now) {
+ return (isActiveWiki(domain) || isEnBetaClusterDomain(domain))
+ && !hasEnded(now);
+}
+
function getAnnouncements(domain) {
return {
// eslint-disable-next-line multiline-ternary
- announce: isActiveWiki(domain) || isEnBetaClusterDomain(domain)
+ announce: isActive(domain, new Date())
? getActiveAnnouncements() : []
};
}
@@ -97,6 +110,7 @@
buildId,
buildAndroidAnnouncement,
buildIosAnnouncement,
- getActiveAnnouncements
+ getActiveAnnouncements,
+ hasEnded
}
};
diff --git a/spec.yaml b/spec.yaml
index 2bd8dd5..95d2a48 100644
--- a/spec.yaml
+++ b/spec.yaml
@@ -85,18 +85,18 @@
headers:
content-type: application/json
body:
- announce:
- - id: /.+/
- type: /.+/
- start_time: /.+/
- end_time: /.+/
- platforms: [ /.+/ ]
- text: /.+/
- action:
- title: /.+/
- url: /.+/
- caption_HTML: /.+/
- countries: [ /.+/ ]
+ announce: []
+# - id: /.+/
+# type: /.+/
+# start_time: /.+/
+# end_time: /.+/
+# platforms: [ /.+/ ]
+# text: /.+/
+# action:
+# title: /.+/
+# url: /.+/
+# caption_HTML: /.+/
+# countries: [ /.+/ ]
# from routes/compilations.js
/{domain}/v1/compilations:
diff --git a/test/lib/feed/announcements.js b/test/lib/feed/announcements.js
index 5531521..b133c8a 100644
--- a/test/lib/feed/announcements.js
+++ b/test/lib/feed/announcements.js
@@ -16,10 +16,11 @@
it('should return some announcements for active wiki', () => {
const res = mut.getAnnouncements(activeAnnouncementDomain);
- assert.ok(res.announce.length === 12);
- assert.equal(res.announce[0].id, 'EN1217FUNDRAISINGANDROIDUS');
- assert.equal(res.announce[1].id, 'EN1217FUNDRAISINGANDROIDGB');
- assert.equal(res.announce[2].id, 'EN1217FUNDRAISINGANDROIDAU');
+ assert.ok(res.announce.length === 0);
+ // assert.ok(res.announce.length === 12);
+ // assert.equal(res.announce[0].id, 'EN1217FUNDRAISINGANDROIDUS');
+ // assert.equal(res.announce[1].id, 'EN1217FUNDRAISINGANDROIDGB');
+ // assert.equal(res.announce[2].id, 'EN1217FUNDRAISINGANDROIDAU');
});
it('should return no images', () => {
@@ -90,6 +91,23 @@
assert.deepEqual(id, id.toUpperCase());
});
+ describe('.hasEnded', () => {
+ it('invalid endTime', () => {
+ config.endTime = 'DISABLED';
+ assert.ok(mut.testing.hasEnded());
+ });
+
+ it('endTime has passed', () => {
+ config.endTime = '2017-12-20T23:59:00Z';
+ assert.ok(mut.testing.hasEnded(new Date(Date.UTC(2017, 11, 21))));
+ });
+
+ it('endTime has not passed yet', () => {
+ config.endTime = '2017-12-20T23:59:00Z';
+ assert.ok(!mut.testing.hasEnded(new Date(Date.UTC(2017, 11, 20))));
+ });
+ });
+
describe('announcements-unit-config', () => {
const THIS_YEAR = new Date().getUTCFullYear();
--
To view, visit https://gerrit.wikimedia.org/r/398254
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id27816938108f82f09f522702dede79d630b630a
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/services/mobileapps
Gerrit-Branch: master
Gerrit-Owner: BearND <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Fjalapeno <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Mhurd <[email protected]>
Gerrit-Reviewer: Ppchelko <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits