2022-03-28 17:24:51 +02:00
|
|
|
const {agentProvider, mockManager, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
2022-04-08 19:06:30 +05:30
|
|
|
const {anyEtag, anyObjectId, anyString} = matchers;
|
2022-03-28 17:24:51 +02:00
|
|
|
|
|
|
|
const newsletterSnapshot = {
|
|
|
|
id: anyObjectId
|
|
|
|
};
|
|
|
|
|
|
|
|
let agent;
|
|
|
|
|
|
|
|
describe('Newsletters API', function () {
|
|
|
|
before(async function () {
|
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init();
|
|
|
|
await agent.loginAsOwner();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
mockManager.restore();
|
|
|
|
});
|
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
it('Can add a newsletter', async function () {
|
|
|
|
const newsletter = {
|
|
|
|
name: 'My test newsletter',
|
|
|
|
sender_name: 'Test',
|
|
|
|
sender_email: 'test@example.com',
|
2022-04-08 19:06:30 +05:30
|
|
|
sender_reply_to: 'newsletter',
|
2022-03-31 10:52:04 +02:00
|
|
|
status: 'active',
|
|
|
|
subscribe_on_signup: true,
|
2022-04-08 19:06:30 +05:30
|
|
|
title_font_category: 'serif',
|
|
|
|
body_font_category: 'serif',
|
|
|
|
show_header_icon: true,
|
|
|
|
show_header_title: true,
|
|
|
|
show_badge: true,
|
2022-03-31 10:52:04 +02:00
|
|
|
sort_order: 0
|
|
|
|
};
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
await agent
|
|
|
|
.post(`newsletters/`)
|
|
|
|
.body({newsletters: [newsletter]})
|
|
|
|
.expectStatus(201)
|
|
|
|
.matchBodySnapshot({
|
2022-04-12 19:44:21 +05:30
|
|
|
newsletters: new Array(1).fill(newsletterSnapshot)
|
2022-03-31 10:52:04 +02:00
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag,
|
|
|
|
location: anyString
|
|
|
|
});
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
await agent.get('newsletters/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
2022-04-12 19:44:21 +05:30
|
|
|
newsletters: new Array(2).fill(newsletterSnapshot)
|
2022-03-31 10:52:04 +02:00
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
it('Can browse newsletters', async function () {
|
|
|
|
await agent.get('newsletters/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
2022-04-12 19:44:21 +05:30
|
|
|
newsletters: new Array(2).fill(newsletterSnapshot)
|
2022-03-31 10:52:04 +02:00
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
it('Can edit newsletters', async function () {
|
|
|
|
const res = await agent.get('newsletters?limit=1')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
newsletters: [newsletterSnapshot]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
const id = res.body.newsletters[0].id;
|
2022-03-28 17:24:51 +02:00
|
|
|
|
2022-03-31 10:52:04 +02:00
|
|
|
await agent.put(`newsletters/${id}`)
|
|
|
|
.body({
|
|
|
|
newsletters: [{
|
|
|
|
name: 'Updated newsletter name'
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
newsletters: [newsletterSnapshot]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
});
|
|
|
|
});
|
2022-03-28 17:24:51 +02:00
|
|
|
});
|