From 9d52d7aae21a303fd97a6691ae567ad93e626706 Mon Sep 17 00:00:00 2001 From: chris48s Date: Thu, 11 Mar 2021 20:11:58 +0000 Subject: [PATCH 1/2] allow missing 'goal' key in [liberapay] badges closes #6254 --- services/liberapay/liberapay-base.js | 3 +-- services/liberapay/liberapay-gives.tester.js | 13 +++++++++++++ services/liberapay/liberapay-goal.tester.js | 11 +++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/services/liberapay/liberapay-base.js b/services/liberapay/liberapay-base.js index 2cbcf2cc3b4fd..8e47ce60e064b 100644 --- a/services/liberapay/liberapay-base.js +++ b/services/liberapay/liberapay-base.js @@ -26,8 +26,7 @@ const schema = Joi.object({ .keys({ amount: Joi.string().required(), }) - .allow(null) - .required(), + .allow(null), }).required() const isCurrencyOverTime = Joi.string().regex( diff --git a/services/liberapay/liberapay-gives.tester.js b/services/liberapay/liberapay-gives.tester.js index 69e364aa6bd29..a7114153f7eb8 100644 --- a/services/liberapay/liberapay-gives.tester.js +++ b/services/liberapay/liberapay-gives.tester.js @@ -12,6 +12,19 @@ t.create('Giving (not found)') .get('/does-not-exist.json') .expectBadge({ label: 'liberapay', message: 'not found' }) +t.create('Goal (missing goal key)') + .get('/Liberapay.json') + .intercept(nock => + nock('https://liberapay.com') + .get('/Liberapay/public.json') + .reply(200, { + npatrons: 0, + giving: { amount: '3.71', currency: 'EUR' }, + receiving: null, + }) + ) + .expectBadge({ label: 'gives', message: isCurrencyOverTime }) + t.create('Giving (null)') .get('/Liberapay.json') .intercept(nock => diff --git a/services/liberapay/liberapay-goal.tester.js b/services/liberapay/liberapay-goal.tester.js index a05aabe9c6aa0..a340d4d5e5b48 100644 --- a/services/liberapay/liberapay-goal.tester.js +++ b/services/liberapay/liberapay-goal.tester.js @@ -8,6 +8,17 @@ t.create('Goal Progress (valid)').get('/Liberapay.json').expectBadge({ message: isIntegerPercentage, }) +t.create('Goal (missing goal key)') + .get('/Liberapay.json') + .intercept(nock => + nock('https://liberapay.com').get('/Liberapay/public.json').reply(200, { + npatrons: 0, + giving: null, + receiving: null, + }) + ) + .expectBadge({ label: 'liberapay', message: 'no public goals' }) + t.create('Goal Progress (not found)') .get('/does-not-exist.json') .expectBadge({ label: 'liberapay', message: 'not found' }) From 6531230356be2d28e8da83a6ca7fa1a635e16a57 Mon Sep 17 00:00:00 2001 From: chris48s Date: Thu, 11 Mar 2021 20:16:59 +0000 Subject: [PATCH 2/2] fix test name --- services/liberapay/liberapay-gives.tester.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/liberapay/liberapay-gives.tester.js b/services/liberapay/liberapay-gives.tester.js index a7114153f7eb8..b91f47a045571 100644 --- a/services/liberapay/liberapay-gives.tester.js +++ b/services/liberapay/liberapay-gives.tester.js @@ -12,7 +12,7 @@ t.create('Giving (not found)') .get('/does-not-exist.json') .expectBadge({ label: 'liberapay', message: 'not found' }) -t.create('Goal (missing goal key)') +t.create('Giving (missing goal key)') .get('/Liberapay.json') .intercept(nock => nock('https://liberapay.com')