diff --git a/test/api-acceptance/admin/email_preview_spec.js b/test/api-acceptance/admin/email_preview_spec.js index 73888c7524..ac473c713e 100644 --- a/test/api-acceptance/admin/email_preview_spec.js +++ b/test/api-acceptance/admin/email_preview_spec.js @@ -4,6 +4,7 @@ const ObjectId = require('bson-objectid'); const testUtils = require('../../utils'); const localUtils = require('./utils'); const config = require('../../../core/server/config'); +const models = require('../../../core/server/models/index'); const ghost = testUtils.startGhost; @@ -68,5 +69,44 @@ describe('Email Preview API', function () { localUtils.API.checkResponse(jsonResponse.email_previews[0], 'email_preview', null, null); }); }); + + it('can read post email preview with email card and replacements', function () { + const post = testUtils.DataGenerator.forKnex.createPost({ + id: ObjectId.generate(), + title: 'Post with email-only card', + slug: 'email-only-card', + mobiledoc: '{"version":"0.3.1","atoms":[],"cards":[["email",{"html":"

Hey {subscriber_firstname \\"there\\"} {unknown}

Welcome to your first Ghost email!

"}],["email",{"html":"

Another email card with a similar replacement, {subscriber_firstname, \\"see?\\"}

"}]],"markups":[],"sections":[[10,0],[1,"p",[[0,[],0,"This is the actual post content..."]]],[10,1],[1,"p",[]]]}', + html: '

This is the actual post content...

', + plaintext: 'This is the actual post content...', + status: 'draft', + uuid: 'd52c42ae-2755-455c-80ec-70b2ec55c904' + }); + + return models.Post.add(post, {context: {internal: true}}).then(() => { + return request + .get(localUtils.API.getApiQuery(`email_preview/posts/${post.id}/`)) + .set('Origin', config.get('url')) + .set('Accept', 'application/json') + .expect('Content-Type', /json/) + .expect('Cache-Control', testUtils.cacheRules.private) + .expect(200) + .then((res) => { + should.not.exist(res.headers['x-cache-invalidate']); + const jsonResponse = res.body; + should.exist(jsonResponse); + should.exist(jsonResponse.email_previews); + + jsonResponse.email_previews[0].html.should.match(/Hey there {unknown}/); + jsonResponse.email_previews[0].html.should.match(/Welcome to your first Ghost email!/); + jsonResponse.email_previews[0].html.should.match(/This is the actual post content\.\.\./); + jsonResponse.email_previews[0].html.should.match(/Another email card with a similar replacement, see\?/); + + jsonResponse.email_previews[0].plaintext.should.match(/Hey there {unknown}/); + jsonResponse.email_previews[0].plaintext.should.match(/Welcome to your first Ghost email!/); + jsonResponse.email_previews[0].plaintext.should.match(/This is the actual post content\.\.\./); + jsonResponse.email_previews[0].plaintext.should.match(/Another email card with a similar replacement, see\?/); + }); + }); + }); }); });