+
+/*
+ Utility function to run testing-library queries over nodes that contain html tags, as in
+ `this includes some bold text
`.
+
+ Usage:
+ const getByTextWithMarkup = withMarkup(screen.getByText)
+ getByTextWithMarkup('this includes some bold text')
+
+ const findByTextWithMarkup = withMarkup(screen.findByText)
+ await findByTextWithMarkup('this includes some bold text')
+ */
+const withMarkup =
+ (query: Query) =>
+ (text: string): Element | Promise =>
+ query((content: string, node: Element | null) => {
+ if (!node) {
+ return false
+ }
+ const hasText = (node: Element) => node.textContent === text
+ const childrenDontHaveText = Array.from(node.children).every(
+ child => !hasText(child as HTMLElement)
+ )
+ return hasText(node) && childrenDontHaveText
+ })
+
+export default withMarkup
diff --git a/services/web/test/unit/src/User/UserEmailsControllerTests.js b/services/web/test/unit/src/User/UserEmailsControllerTests.js
index 2542a65b6b..fad68cd277 100644
--- a/services/web/test/unit/src/User/UserEmailsControllerTests.js
+++ b/services/web/test/unit/src/User/UserEmailsControllerTests.js
@@ -14,7 +14,11 @@ describe('UserEmailsController', function () {
this.req.sessionID = Math.random().toString()
this.res = new MockResponse()
this.next = sinon.stub()
- this.user = { _id: 'mock-user-id', email: 'example@overleaf.com' }
+ this.user = {
+ _id: 'mock-user-id',
+ email: 'example@overleaf.com',
+ emails: {},
+ }
this.UserGetter = {
getUserFullEmails: sinon.stub(),
@@ -234,6 +238,28 @@ describe('UserEmailsController', function () {
})
this.UserEmailsController.add(this.req, this.res, this.next)
})
+
+ it('should fail to add new emails when the limit has been reached', function (done) {
+ this.user.emails = []
+ for (let i = 0; i < 10; i++) {
+ this.user.emails.push({ email: `example${i}@overleaf.com` })
+ }
+ this.UserEmailsController.add(
+ this.req,
+ {
+ status: code => {
+ expect(code).to.equal(422)
+ return {
+ json: error => {
+ expect(error.message).to.equal('secondary email limit exceeded')
+ done()
+ },
+ }
+ },
+ },
+ this.next
+ )
+ })
})
describe('remove', function () {