-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Captcha to data attribute forms
ref BAE-370 Enables Captcha (when labs flag and config entry set) in data-attribute forms within Portal.
- Loading branch information
Showing
5 changed files
with
206 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,16 @@ describe('Member Data attributes:', () => { | |
}]; | ||
}); | ||
|
||
// Mock hCaptcha | ||
window.hcaptcha = { | ||
execute: () => { } | ||
}; | ||
jest.spyOn(window.hcaptcha, 'execute').mockImplementation(() => { | ||
return Promise.resolve({ | ||
response: 'testresponse' | ||
}); | ||
}); | ||
|
||
// Mock window.location | ||
let locationMock = jest.fn(); | ||
delete window.location; | ||
|
@@ -169,6 +179,31 @@ describe('Member Data attributes:', () => { | |
}); | ||
expect(window.fetch).toHaveBeenLastCalledWith('https://portal.localhost/members/api/send-magic-link/', {body: expectedBody, headers: {'Content-Type': 'application/json'}, method: 'POST'}); | ||
}); | ||
|
||
test('submits captcha response if captcha id specified', async () => { | ||
const {event, form, errorEl, siteUrl, submitHandler} = getMockData(); | ||
|
||
await formSubmitHandler({event, form, errorEl, siteUrl, submitHandler, captchaId: '123123'}); | ||
|
||
expect(window.fetch).toHaveBeenCalledTimes(2); | ||
const expectedBody = JSON.stringify({ | ||
email: '[email protected]', | ||
emailType: 'signup', | ||
labels: ['Gold'], | ||
name: 'Jamie Larsen', | ||
autoRedirect: true, | ||
urlHistory: [{ | ||
path: '/blog/', | ||
refMedium: null, | ||
refSource: 'ghost-explore', | ||
refUrl: 'https://example.com/blog/', | ||
time: 1611234567890 | ||
}], | ||
token: 'testresponse', | ||
integrityToken: 'testtoken' | ||
}); | ||
expect(window.fetch).toHaveBeenLastCalledWith('https://portal.localhost/members/api/send-magic-link/', {body: expectedBody, headers: {'Content-Type': 'application/json'}, method: 'POST'}); | ||
}); | ||
}); | ||
|
||
describe('data-members-plan', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
ghost/core/test/unit/frontend/helpers/__snapshots__/ghost_head.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters