From cc72e8f599c8e1f0b03898841862ad1dff025d12 Mon Sep 17 00:00:00 2001 From: Naz Date: Tue, 8 Nov 2022 11:47:00 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20complimentary=5Fplan=20M?= =?UTF-8?q?ember=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Team/issues/2219 - The CSV importer was failing when a "complimentary_plan" flag was present with a "true" value. The root of the issue was the data model change where the "id" of the Tier object is no longer a String but an ObjectID instance. It's a slight departure from previous bookshelf object behavior where 'id' property is always a string that is a stringified ObjectID. - In the future we should unify the logic across all data access objects to either keep the convention of using a String under id property or switch to ObjectId instances. --- ghost/members-importer/lib/importer.js | 2 +- ghost/members-importer/test/importer.test.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ghost/members-importer/lib/importer.js b/ghost/members-importer/lib/importer.js index ed00c8c54a..74990f36d1 100644 --- a/ghost/members-importer/lib/importer.js +++ b/ghost/members-importer/lib/importer.js @@ -161,7 +161,7 @@ module.exports = class MembersCSVImporter { }, options); } else if (row.complimentary_plan) { await membersRepository.update({ - products: [{id: defaultTier.id}] + products: [{id: defaultTier.id.toString()}] }, { ...options, id: member.id diff --git a/ghost/members-importer/test/importer.test.js b/ghost/members-importer/test/importer.test.js index 14ff8f3b78..b9e0b0e6a6 100644 --- a/ghost/members-importer/test/importer.test.js +++ b/ghost/members-importer/test/importer.test.js @@ -2,6 +2,8 @@ // const testUtils = require('./utils'); require('./utils'); +const Tier = require('@tryghost/tiers/lib/Tier'); +const ObjectID = require('bson-objectid').default; const assert = require('assert'); const fs = require('fs-extra'); const path = require('path'); @@ -16,6 +18,7 @@ describe('Importer', function () { let knexStub; let sendEmailStub; let membersRepositoryStub; + let defaultTierId; const defaultAllowedFields = { email: 'email', @@ -43,9 +46,10 @@ describe('Importer', function () { }); const buildMockImporterInstance = () => { - const defaultTierDummy = { - id: 'default_tier_id' - }; + defaultTierId = new ObjectID(); + const defaultTierDummy = new Tier({ + id: defaultTierId + }); memberCreateStub = sinon.stub().resolves({ id: `test_member_id` @@ -200,7 +204,7 @@ describe('Importer', function () { // complimentary_plan import membersRepositoryStub.update.calledOnce.should.be.true(); should.deepEqual(membersRepositoryStub.update.args[0][0].products, [{ - id: 'default_tier_id' + id: defaultTierId.toString() }]); should.deepEqual(membersRepositoryStub.update.args[0][1].id, 'test_member_id'); });