From 9da57fa6bb52fe4a7f2e5732209bb09dd1229e5a Mon Sep 17 00:00:00 2001 From: Hannah Wolfe Date: Sun, 24 Apr 2022 14:18:00 +0100 Subject: [PATCH] Updated test fixtures for multiple newsletters - Updated the member fixtures to have 6 subscribed and 2 unsubscribed members - Added an inactive newsletter - Updated newsletter-member relations to reflect the 6 subscribed and 2 unsubscribed, but with different cases: - 3 subscribed to default - 1 subscribed to secondary only - 1 subscribed to default + secondary - 1 subscribed to secondary + inactive - 1 subscribed to inactive only (i.e. not subscribed) - 1 not subscribed at all - With these changes, I needed to update the members snap as 2 members appear as subscribed:false in many tests - I also needed to update some posts regression tests, as 2 less members get emailed in 2 tests --- .../admin/__snapshots__/members.test.js.snap | 36 +++++----- test/regression/api/admin/posts.test.js | 22 +++--- test/utils/fixture-utils.js | 16 ++++- test/utils/fixtures/data-generator.js | 71 +++++++++++++++++-- 4 files changed, 110 insertions(+), 35 deletions(-) diff --git a/test/e2e-api/admin/__snapshots__/members.test.js.snap b/test/e2e-api/admin/__snapshots__/members.test.js.snap index fef15d18c8..56ddb89ffd 100644 --- a/test/e2e-api/admin/__snapshots__/members.test.js.snap +++ b/test/e2e-api/admin/__snapshots__/members.test.js.snap @@ -494,7 +494,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -514,7 +514,7 @@ Object { "name": "Dana Barrett", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -537,7 +537,7 @@ exports[`Members API Can browse 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "8426", + "content-length": "8428", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -1083,7 +1083,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1103,7 +1103,7 @@ Object { "name": "Dana Barrett", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1126,7 +1126,7 @@ exports[`Members API Can filter by paid status 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "6891", + "content-length": "6893", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -1152,7 +1152,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1175,7 +1175,7 @@ exports[`Members API Can filter using contains operators 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "664", + "content-length": "665", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -1261,7 +1261,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1281,7 +1281,7 @@ Object { "name": "Dana Barrett", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1304,7 +1304,7 @@ exports[`Members API Can ignore any unknown includes 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "6891", + "content-length": "6893", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", @@ -1450,7 +1450,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1470,7 +1470,7 @@ Object { "name": "Dana Barrett", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1639,7 +1639,7 @@ Object { "name": "Peter Venkman", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -1659,7 +1659,7 @@ Object { "name": "Dana Barrett", "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -2377,7 +2377,7 @@ Object { "newsletters": Any, "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -2398,7 +2398,7 @@ Object { "newsletters": Any, "note": null, "status": "paid", - "subscribed": true, + "subscribed": false, "subscriptions": Any, "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/, "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, @@ -2421,7 +2421,7 @@ exports[`Members API: with multiple newsletters Can browse 2: [headers] 1`] = ` Object { "access-control-allow-origin": "http://127.0.0.1:2369", "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", - "content-length": "8562", + "content-length": "8564", "content-type": "application/json; charset=utf-8", "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, "vary": "Origin, Accept-Encoding", diff --git a/test/regression/api/admin/posts.test.js b/test/regression/api/admin/posts.test.js index e86e20e279..b785382d3f 100644 --- a/test/regression/api/admin/posts.test.js +++ b/test/regression/api/admin/posts.test.js @@ -410,7 +410,7 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res.body.posts); should.exist(res.body.posts[0].title); res.body.posts[0].title.should.equal('Tags test 5'); @@ -420,7 +420,7 @@ describe('Posts API (canary)', function () { // Expected behaviour when creating a slug with spaces: res.body.posts[0].tags[0].name.should.equal('five-spaces'); - // If we create another post again now that the five-spaces tag exists, + // If we create another post again now that the five-spaces tag exists, // we need to make sure it matches correctly and doesn't create a new tag again const res2 = await request @@ -435,7 +435,7 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res2.body.posts); should.exist(res2.body.posts[0].title); res2.body.posts[0].title.should.equal('Tags test 6'); @@ -458,7 +458,7 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res.body.posts); should.exist(res.body.posts[0].title); res.body.posts[0].title.should.equal('Tags test 7'); @@ -466,7 +466,7 @@ describe('Posts API (canary)', function () { res.body.posts[0].tags[0].slug.should.equal('six-spaces'); res.body.posts[0].tags[0].name.should.equal('Not automated name for six spaces'); - // If we create another post again now that the five-spaces tag exists, + // If we create another post again now that the five-spaces tag exists, // we need to make sure it matches correctly and doesn't create a new tag again const res2 = await request @@ -481,7 +481,7 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res2.body.posts); should.exist(res2.body.posts[0].title); res2.body.posts[0].title.should.equal('Tags test 8'); @@ -504,14 +504,14 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res.body.posts); should.exist(res.body.posts[0].title); res.body.posts[0].title.should.equal('Tags test 9'); res.body.posts[0].tags.length.should.equal(1); res.body.posts[0].tags[0].slug.should.equal(tooLongSlug.substring(0, 185)); - // If we create another post again now that the very long tag exists, + // If we create another post again now that the very long tag exists, // we need to make sure it matches correctly and doesn't create a new tag again const res2 = await request @@ -526,7 +526,7 @@ describe('Posts API (canary)', function () { .expect('Content-Type', /json/) .expect('Cache-Control', testUtils.cacheRules.private) .expect(201); - + should.exist(res2.body.posts); should.exist(res2.body.posts[0].title); res2.body.posts[0].title.should.equal('Tags test 10'); @@ -604,7 +604,7 @@ describe('Posts API (canary)', function () { publishedRes.body.posts[0].status.should.equal('sent'); should.exist(publishedRes.body.posts[0].email); - publishedRes.body.posts[0].email.email_count.should.equal(8); + publishedRes.body.posts[0].email.email_count.should.equal(6); }); it('publishes a post while setting email_only flag sends an email', async function () { @@ -647,7 +647,7 @@ describe('Posts API (canary)', function () { publishedRes.body.posts[0].status.should.equal('sent'); should.exist(publishedRes.body.posts[0].email); - publishedRes.body.posts[0].email.email_count.should.equal(5); + publishedRes.body.posts[0].email.email_count.should.equal(3); }); it('read-only value do not cause errors when edited', function () { diff --git a/test/utils/fixture-utils.js b/test/utils/fixture-utils.js index 78886eb2da..64e0befd6d 100644 --- a/test/utils/fixture-utils.js +++ b/test/utils/fixture-utils.js @@ -465,7 +465,7 @@ const fixtures = { return models.Product.add(archivedProduct, context.internal); }, - insertMembersAndLabelsAndProducts: function insertMembersAndLabelsAndProducts() { + insertMembersAndLabelsAndProducts: function insertMembersAndLabelsAndProducts(newsletters = false) { return Promise.map(DataGenerator.forKnex.labels, function (label) { return models.Label.add(label, context.internal); }).then(function () { @@ -504,6 +504,15 @@ const fixtures = { member.labels = memberLabelRelations; + if (newsletters) { + let memberNewsletterRelations = _.filter(DataGenerator.forKnex.members_newsletters, {member_id: member.id}); + memberNewsletterRelations = _.map(memberNewsletterRelations, function (memberNewsletterRelation) { + return _.find(DataGenerator.forKnex.newsletters, {id: memberNewsletterRelation.newsletter_id}); + }); + + member.newsletters = memberNewsletterRelations; + } + // TODO: replace with full member/product associations if (member.email === 'with-product@test.com') { member.products = [{slug: product.get('slug')}]; @@ -634,11 +643,14 @@ const toDoList = { return fixtures.insertOne('Member', 'members', 'createMember'); }, members: function insertMembersAndLabelsAndProducts() { - return fixtures.insertMembersAndLabelsAndProducts(); + return fixtures.insertMembersAndLabelsAndProducts(false); }, newsletters: function insertNewsletters() { return fixtures.insertNewsletters(); }, + 'members:newsletters': function insertMembersAndLabelsAndProductsAndNewsletters() { + return fixtures.insertMembersAndLabelsAndProducts(true); + }, 'members:emails': function insertEmailsAndRecipients() { return fixtures.insertEmailsAndRecipients(); }, diff --git a/test/utils/fixtures/data-generator.js b/test/utils/fixtures/data-generator.js index 9dc3e5900f..0e6f79bc71 100644 --- a/test/utils/fixtures/data-generator.js +++ b/test/utils/fixtures/data-generator.js @@ -354,14 +354,16 @@ DataGenerator.Content = { email: 'vip-paid@test.com', name: 'Peter Venkman', uuid: 'f6f91461-d7d8-4a3f-aa5d-8e582c40b346', - status: 'paid' + status: 'paid', + subscribed: false }, { id: ObjectId().toHexString(), email: 'with-product@test.com', name: 'Dana Barrett', uuid: 'f6f91461-d7d8-4a3f-aa5d-8e582c40b347', - status: 'paid' + status: 'paid', + subscribed: false } ], @@ -399,6 +401,23 @@ DataGenerator.Content = { show_header_title: true, show_badge: true, sort_order: 2 + }, + { + id: ObjectId().toHexString(), + name: 'Old newsletter', + slug: 'old-newsletter', + description: '', + sender_name: 'Jamie', + sender_email: 'jamie@example.com', + sender_reply_to: 'newsletter', + status: 'inactive', + subscribe_on_signup: true, + title_font_category: 'serif', + body_font_category: 'serif', + show_header_icon: true, + show_header_title: true, + show_badge: true, + sort_order: 2 } ], @@ -1233,9 +1252,53 @@ DataGenerator.forKnex = (function () { const members_newsletters = [ { id: ObjectId().toHexString(), - member_id: DataGenerator.Content.posts[0].id, - newsletter_id: DataGenerator.Content.tags[0].id + member_id: DataGenerator.Content.members[0].id, + newsletter_id: DataGenerator.Content.newsletters[0].id + }, + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[1].id, + newsletter_id: DataGenerator.Content.newsletters[0].id + }, + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[2].id, + newsletter_id: DataGenerator.Content.newsletters[0].id + }, + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[3].id, + newsletter_id: DataGenerator.Content.newsletters[1].id + }, + // Member index 4 (comped@test.com), subscribed to two active newsletters + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[4].id, + newsletter_id: DataGenerator.Content.newsletters[0].id + }, + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[4].id, + newsletter_id: DataGenerator.Content.newsletters[1].id + }, + // Member index 5 (vip@test.com), subscribed to an active and inactive newsletter + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[5].id, + newsletter_id: DataGenerator.Content.newsletters[1].id + }, + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[5].id, + newsletter_id: DataGenerator.Content.newsletters[2].id + }, + // Member index 6 (vip-paid@test.com), subscribed to an inactive newsletter + { + id: ObjectId().toHexString(), + member_id: DataGenerator.Content.members[6].id, + newsletter_id: DataGenerator.Content.newsletters[2].id } + // Member index 7 (with-product@test.com), subscribed to no newsletter ]; const posts_authors = [