From a4c78dbf193d7fafa12e1dd7c2a3048c6fa6f4c0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 19 May 2021 22:32:15 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20error=20on=20saving=20me?= =?UTF-8?q?mber=20with=20susbcriptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Team/issues/699 With custom products, saving a member with subscriptions on member detail page in Admin throws errors on console, though the save is successful. This breaks the Admin as user needs to refresh the screen again to get rid of error. This change - - updates the response on member save to return `price` object in subscription - updates tests --- core/server/api/canary/members.js | 2 +- .../api/canary/admin/members_spec.js | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/core/server/api/canary/members.js b/core/server/api/canary/members.js index 6171602635..10b7484d69 100644 --- a/core/server/api/canary/members.js +++ b/core/server/api/canary/members.js @@ -200,7 +200,7 @@ module.exports = { await member.load(['stripeSubscriptions']); } - await member.load(['stripeSubscriptions.customer']); + await member.load(['stripeSubscriptions.customer', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']); return member; } catch (error) { diff --git a/test/regression/api/canary/admin/members_spec.js b/test/regression/api/canary/admin/members_spec.js index b89dcabd8f..4520ff665a 100644 --- a/test/regression/api/canary/admin/members_spec.js +++ b/test/regression/api/canary/admin/members_spec.js @@ -206,6 +206,47 @@ describe('Members API (canary)', function () { }); }); + it('Paid members subscriptions has price data', function () { + const memberChanged = { + name: 'Updated name' + }; + return request + .get(localUtils.API.getApiQuery('members/?search=egon&paid=true')) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200) + .then((res) => { + should.not.exist(res.headers['x-cache-invalidate']); + const jsonResponse = res.body; + should.exist(jsonResponse); + should.exist(jsonResponse.members); + jsonResponse.members.should.have.length(1); + should.exist(jsonResponse.members[0].subscriptions[0].price); + return jsonResponse.members[0]; + }).then((paidMember) => { + return request + .put(localUtils.API.getApiQuery(`members/${paidMember.id}/`)) + .send({members: [memberChanged]}) + .set('Origin', config.get('url')) + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200) + .then((res) => { + should.not.exist(res.headers['x-cache-invalidate']); + + const jsonResponse = res.body; + + should.exist(jsonResponse); + should.exist(jsonResponse.members); + jsonResponse.members.should.have.length(1); + localUtils.API.checkResponse(jsonResponse.members[0], 'member', ['subscriptions', 'products']); + should.exist(jsonResponse.members[0].subscriptions[0].price); + jsonResponse.members[0].name.should.equal(memberChanged.name); + }); + }); + }); + it('Add should fail when passing incorrect email_type query parameter', function () { const member = { name: 'test',