diff --git a/ghost/core/test/e2e-api/admin/__snapshots__/email-previews.test.js.snap b/ghost/core/test/e2e-api/admin/__snapshots__/email-previews.test.js.snap new file mode 100644 index 0000000000..113f100d4f --- /dev/null +++ b/ghost/core/test/e2e-api/admin/__snapshots__/email-previews.test.js.snap @@ -0,0 +1,2423 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Email Preview API As Admin can send test email 1: [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", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API As Author cannot send test email 1: [body] 1`] = ` +Object { + "errors": Array [ + Object { + "code": null, + "context": null, + "details": null, + "ghostErrorCode": null, + "help": null, + "id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "message": "You do not have permission to sendTestEmail email_previews", + "property": null, + "type": "NoPermissionError", + }, + ], +} +`; + +exports[`Email Preview API As Author cannot send test email 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": "248", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API As Editor can send test email 1: [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", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API As Owner can send test email 1: [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", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read can read post email preview with email card and replacements 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +Post with email-only card + + + + + This is the actual post content... + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ Post with email-only card +
+ + + + +
+ By Joe Bloggs – + 01 Jan 1970 – + View online → +
+
+ +

Hey there {unknown}

Welcome to your first Ghost email!

This is the actual post content...

Another email card with a similar replacement, see?

+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "Hey there {unknown} + +Welcome to your first Ghost email! + +This is the actual post content... + +Another email card with a similar replacement, see?", + "subject": "Post with email-only card", + }, + ], +} +`; + +exports[`Email Preview API Read can read post email preview with email card and replacements 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": "18192", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read can read post email preview with fields 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +HTML Ipsum + + + + + This is my custom excerpt! + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ HTML Ipsum +
+ + + + +
+ By Joe Bloggs – + 01 Jan 2015 – + View online → +
+
+ +

HTML Ipsum Presents

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis.

Header Level 2

  1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  2. Aliquam tincidunt mauris eu risus.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.

Header Level 3

  • Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  • Aliquam tincidunt mauris eu risus.
#header h1 a{display: block;width: 300px;height: 80px;}
+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "HTML Ipsum Presents + +Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim [\\\\\\"#\\\\\\"] in turpis pulvinar facilisis. Ut felis. + + +Header Level 2 + + 1. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. + 2. Aliquam tincidunt mauris eu risus. + +> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est. + + +Header Level 3 + + * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. + * Aliquam tincidunt mauris eu risus. + +#header h1 a{display: block;width: 300px;height: 80px;}", + "subject": "HTML Ipsum", + }, + ], +} +`; + +exports[`Email Preview API Read can read post email preview with fields 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": "22959", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read can't retrieve for non existent post 1: [body] 1`] = ` +Object { + "errors": Array [ + Object { + "code": null, + "context": "Post not found.", + "details": null, + "ghostErrorCode": null, + "help": null, + "id": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "message": "Resource not found error, cannot read email_preview.", + "property": null, + "type": "NotFoundError", + }, + ], +} +`; + +exports[`Email Preview API Read can't retrieve for non existent post 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": "251", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read has custom content transformations for email compatibility 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +Post with email-only card + + + + + Testing links in email excerpt and apostrophes ' + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ Post with email-only card +
+ + + + +
+ By Joe Bloggs – + 01 Jan 1970 – + View online → +
+
+ +

Testing links in email excerpt and apostrophes '

+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "Testing links [https://ghost.org] in email excerpt and apostrophes '", + "subject": "Post with email-only card", + }, + ], +} +`; + +exports[`Email Preview API Read has custom content transformations for email compatibility 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": "17954", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read uses the newsletter provided through ?newsletter=slug 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +Post with email-only card + + + + + Testing links in email excerpt and apostrophes ' + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ Post with email-only card +
+ + + + +
+ By Joe Bloggs – + 01 Jan 1970 – + View online → +
+
+ +

Testing links in email excerpt and apostrophes '

+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "Testing links [https://ghost.org] in email excerpt and apostrophes '", + "subject": "Post with email-only card", + }, + ], +} +`; + +exports[`Email Preview API Read uses the newsletter provided through ?newsletter=slug 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": "18320", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read uses the posts newsletter 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +Post with email-only card + + + + + Testing links in email excerpt and apostrophes ' + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ Post with email-only card +
+ + + + +
+ By Joe Bloggs – + 01 Sep 2022 – + View online → +
+
+ +

Testing links in email excerpt and apostrophes '

+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "Testing links [https://ghost.org] in email excerpt and apostrophes '", + "subject": "Post with email-only card", + }, + ], +} +`; + +exports[`Email Preview API Read uses the posts newsletter 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": "18320", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Email Preview API Read uses the posts newsletter by default 1: [body] 1`] = ` +Object { + "email_previews": Array [ + Object { + "html": " + + + + + +Post with email-only card + + + + + Testing links in email excerpt and apostrophes ' + + + + + + + + + + + + + +
  +
+ + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +
+
+ Post with email-only card +
+ + + + +
+ By Joe Bloggs – + 01 Jan 1970 – + View online → +
+
+ +

Testing links in email excerpt and apostrophes '

+ +
+
+ + + + + + + + + + + +
Ghost © 2022 – Unsubscribe
\\"Powered
+
+ +
+
 
+ + +", + "plaintext": "Testing links [https://ghost.org] in email excerpt and apostrophes '", + "subject": "Post with email-only card", + }, + ], +} +`; + +exports[`Email Preview API Read uses the posts newsletter by default 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": "18320", + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Origin, Accept-Encoding", + "x-powered-by": "Express", +} +`; diff --git a/ghost/core/test/utils/fixture-utils.js b/ghost/core/test/utils/fixture-utils.js index a8f49e07cf..49cc03a39e 100644 --- a/ghost/core/test/utils/fixture-utils.js +++ b/ghost/core/test/utils/fixture-utils.js @@ -277,17 +277,21 @@ const fixtures = { }); }, - createUsersWithoutOwner: function createUsersWithoutOwner() { + createUsersWithoutOwner: async function createUsersWithoutOwner() { const usersWithoutOwner = _.cloneDeep(DataGenerator.forKnex.users.slice(1)); + let roles = await models.Role.fetchAll(); + roles = roles.toJSON(); + return Promise.map(usersWithoutOwner, function (user) { let userRolesRelations = _.filter(DataGenerator.forKnex.roles_users, {user_id: user.id}); userRolesRelations = _.map(userRolesRelations, function (userRolesRelation) { - return _.find(DataGenerator.forKnex.roles, {id: userRolesRelation.role_id}); + return _.find(roles, {name: userRolesRelation.role_name}); }); user.roles = userRolesRelations; + return models.User.add(user, context.internal); }); }, diff --git a/ghost/core/test/utils/fixtures/data-generator.js b/ghost/core/test/utils/fixtures/data-generator.js index 10713df3cf..bec860f34f 100644 --- a/ghost/core/test/utils/fixtures/data-generator.js +++ b/ghost/core/test/utils/fixtures/data-generator.js @@ -1284,27 +1284,37 @@ DataGenerator.forKnex = (function () { const roles_users = [ { + // owner id: ObjectId().toHexString(), + role_name: 'Owner', user_id: DataGenerator.Content.users[0].id, role_id: DataGenerator.Content.roles[3].id }, { + // admin id: ObjectId().toHexString(), + role_name: 'Administrator', user_id: DataGenerator.Content.users[1].id, role_id: DataGenerator.Content.roles[0].id }, { + // editor id: ObjectId().toHexString(), + role_name: 'Editor', user_id: DataGenerator.Content.users[2].id, role_id: DataGenerator.Content.roles[1].id }, { + // author id: ObjectId().toHexString(), + role_name: 'Author', user_id: DataGenerator.Content.users[3].id, role_id: DataGenerator.Content.roles[2].id }, { + // contributor id: ObjectId().toHexString(), + role_name: 'Contributor', user_id: DataGenerator.Content.users[7].id, role_id: DataGenerator.Content.roles[4].id }