0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added missing settings endpoint tests

- Added a test for each of the 3 missing endpoints
- This is so that we can be sure future refactors won't break these endpoints
This commit is contained in:
Hannah Wolfe 2022-03-18 17:05:46 +00:00
parent c66eeb5879
commit 68c1bc0285
2 changed files with 124 additions and 2 deletions

View file

@ -1122,3 +1122,45 @@ Object {
"x-powered-by": "Express",
}
`;
exports[`Settings API can do disconnectStripeConnectIntegration 1: [body] 1`] = `Object {}`;
exports[`Settings API can do disconnectStripeConnectIntegration 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": "2",
"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[`Settings API can do updateMembersEmail 1: [body] 1`] = `Object {}`;
exports[`Settings API can do updateMembersEmail 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": "2",
"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[`Settings API can do validateMembersEmailUpdate 1: [body] 1`] = `Object {}`;
exports[`Settings API can do validateMembersEmailUpdate 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": "101",
"content-type": "text/plain; charset=utf-8",
"location": "http://127.0.0.1:2369/ghost/#/settings/members-email/?fromAddressUpdate=success",
"vary": "Origin, Accept, Accept-Encoding",
"x-powered-by": "Express",
}
`;

View file

@ -1,4 +1,5 @@
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
const assert = require('assert');
const {agentProvider, fixtureManager, mockManager, matchers} = require('../../utils/e2e-framework');
const {stringMatching, anyEtag, anyObjectId, anyISODateTime} = matchers;
const CURRENT_SETTINGS_COUNT = 86;
@ -28,12 +29,22 @@ const matchSettingsArray = (length) => {
};
describe('Settings API', function () {
let agent;
let agent, membersService;
before(async function () {
agent = await agentProvider.getAdminAPIAgent();
await fixtureManager.init();
await agent.loginAsOwner();
membersService = require('../../../core/server/services/members');
});
beforeEach(function () {
mockManager.mockMail();
});
afterEach(function () {
mockManager.restore();
});
it('Can request all settings', async function () {
@ -152,4 +163,73 @@ describe('Settings API', function () {
etag: anyEtag
});
});
it('can do updateMembersEmail', async function () {
await agent
.post('settings/members/email/')
.body({
email: 'test@test.com',
type: 'fromAddressUpdate'
})
.expectStatus(200)
.matchBodySnapshot()
.matchHeaderSnapshot({
etag: anyEtag
});
mockManager.assert.sentEmail({to: 'test@test.com'});
});
it('can do validateMembersEmailUpdate', async function () {
const magicLink = await membersService.api.getMagicLink('test@test.com');
const magicLinkUrl = new URL(magicLink);
const token = magicLinkUrl.searchParams.get('token');
// @TODO Fixing https://github.com/TryGhost/Team/issues/584 should result in this test changing
await agent
.get(`settings/members/email/?token=${token}&action=fromAddressUpdate`)
.expectStatus(302)
.matchBodySnapshot()
.matchHeaderSnapshot();
// Assert that the setting is changed as a side effect
// NOTE: cannot use read here :/
await agent.get('settings/')
.expect(({body}) => {
const fromAddress = body.settings.find((setting) => {
return setting.key === 'members_from_address';
});
assert.equal(fromAddress.value, 'test@test.com');
});
});
it('can do disconnectStripeConnectIntegration', async function () {
await agent
.delete('/settings/stripe/connect/')
.expectStatus(200)
.matchBodySnapshot()
.matchHeaderSnapshot({
etag: anyEtag
});
const stripeSettings = [
'stripe_connect_publishable_key',
'stripe_connect_secret_key',
'stripe_connect_livemode',
'stripe_connect_display_name',
'stripe_connect_account_id',
'members_stripe_webhook_id',
'members_stripe_webhook_secret'
];
// Assert that the settings are changed as a side effect
await agent.get('settings/')
.expect(({body}) => {
body.settings.forEach((setting) => {
if (stripeSettings.includes(setting.key)) {
assert.equal(setting.value, null);
}
});
});
});
});