🐛 Fixed complimentary_plan Member imports

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.
This commit is contained in:
Naz 2022-11-08 11:47:00 +07:00
parent 8fa9f1e7e6
commit cc72e8f599
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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');
});