From 95c8ba11d6c43d5a8335445f7d679969ce988d77 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Tue, 19 Sep 2023 16:47:34 +0200 Subject: [PATCH] Added E2E tests for Public Site Settings in members API (#18223) fixes https://github.com/TryGhost/Product/issues/3901 --- .../members/__snapshots__/site.test.js.snap | 59 +++++++++++++++++++ ghost/core/test/e2e-api/members/site.test.js | 48 +++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 ghost/core/test/e2e-api/members/__snapshots__/site.test.js.snap create mode 100644 ghost/core/test/e2e-api/members/site.test.js diff --git a/ghost/core/test/e2e-api/members/__snapshots__/site.test.js.snap b/ghost/core/test/e2e-api/members/__snapshots__/site.test.js.snap new file mode 100644 index 0000000000..1d0e0e47a4 --- /dev/null +++ b/ghost/core/test/e2e-api/members/__snapshots__/site.test.js.snap @@ -0,0 +1,59 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Site Public Settings Can retrieve site pubic config 1: [body] 1`] = ` +Object { + "site": Object { + "accent_color": "#FF1A75", + "allow_self_signup": true, + "cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg", + "description": "Thoughts, stories and ideas", + "icon": null, + "locale": "en", + "logo": null, + "title": "Ghost", + "url": "http://127.0.0.1:2369/", + "version": StringMatching /\\\\d\\+\\\\\\.\\\\d\\+/, + }, +} +`; + +exports[`Site Public Settings Can retrieve site pubic config 2: [headers] 1`] = ` +Object { + "access-control-allow-origin": "*", + "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", + "content-length": StringMatching /\\\\d\\+/, + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Accept-Encoding", + "x-powered-by": "Express", +} +`; + +exports[`Site Public Settings Sets allow_self_signup to false when members are invite only 1: [body] 1`] = ` +Object { + "site": Object { + "accent_color": "#FF1A75", + "allow_self_signup": false, + "cover_image": "https://static.ghost.org/v5.0.0/images/publication-cover.jpg", + "description": "Thoughts, stories and ideas", + "icon": null, + "locale": "en", + "logo": null, + "title": "Ghost", + "url": "http://127.0.0.1:2369/", + "version": StringMatching /\\\\d\\+\\\\\\.\\\\d\\+/, + }, +} +`; + +exports[`Site Public Settings Sets allow_self_signup to false when members are invite only 2: [headers] 1`] = ` +Object { + "access-control-allow-origin": "*", + "cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0", + "content-length": StringMatching /\\\\d\\+/, + "content-type": "application/json; charset=utf-8", + "etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/, + "vary": "Accept-Encoding", + "x-powered-by": "Express", +} +`; diff --git a/ghost/core/test/e2e-api/members/site.test.js b/ghost/core/test/e2e-api/members/site.test.js new file mode 100644 index 0000000000..6c44ac55c6 --- /dev/null +++ b/ghost/core/test/e2e-api/members/site.test.js @@ -0,0 +1,48 @@ +const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework'); +const {anyEtag, stringMatching, anyContentLength} = matchers; +const assert = require('assert/strict'); +const models = require('../../../core/server/models'); + +describe('Site Public Settings', function () { + let membersAgent; + + before(async function () { + membersAgent = await agentProvider.getMembersAPIAgent(); + await fixtureManager.init(); + }); + + it('Can retrieve site pubic config', async function () { + const {body} = await membersAgent + .get('/api/site') + .matchBodySnapshot({ + site: { + version: stringMatching(/\d+\.\d+/) + } + }) + .matchHeaderSnapshot({ + etag: anyEtag, + 'content-length': anyContentLength + }); + assert.equal(body.site.allow_self_signup, true); + }); + + it('Sets allow_self_signup to false when members are invite only', async function () { + await await models.Settings.edit({ + key: 'members_signup_access', + value: 'invite' + }, {context: {internal: true}}); + + const {body} = await membersAgent + .get('/api/site') + .matchBodySnapshot({ + site: { + version: stringMatching(/\d+\.\d+/) + } + }) + .matchHeaderSnapshot({ + etag: anyEtag, + 'content-length': anyContentLength + }); + assert.equal(body.site.allow_self_signup, false); + }); +});