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
This commit is contained in:
Hannah Wolfe 2022-04-24 14:18:00 +01:00 committed by Matt Hanley
parent 48799e1c68
commit 9da57fa6bb
4 changed files with 110 additions and 35 deletions

View File

@ -494,7 +494,7 @@ Object {
"name": "Peter Venkman",
"note": null,
"status": "paid",
"subscribed": true,
"subscribed": false,
"subscriptions": Any<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"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<Array>,
"note": null,
"status": "paid",
"subscribed": true,
"subscribed": false,
"subscriptions": Any<Array>,
"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<Array>,
"note": null,
"status": "paid",
"subscribed": true,
"subscribed": false,
"subscriptions": Any<Array>,
"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",

View File

@ -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 () {

View File

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

View File

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