2022-01-27 13:57:51 +03:00
|
|
|
// Switch these lines once there are useful utils
|
|
|
|
// const testUtils = require('./utils');
|
|
|
|
const sinon = require('sinon');
|
2023-01-04 13:22:12 +03:00
|
|
|
const assert = require('assert');
|
2022-01-27 13:57:51 +03:00
|
|
|
require('./utils');
|
2022-04-13 19:35:24 +03:00
|
|
|
const VerificationTrigger = require('../index');
|
2022-02-03 18:02:33 +03:00
|
|
|
const DomainEvents = require('@tryghost/domain-events');
|
2022-10-06 08:50:27 +03:00
|
|
|
const {MemberCreatedEvent} = require('@tryghost/member-events');
|
2022-01-27 13:57:51 +03:00
|
|
|
|
|
|
|
describe('Import threshold', function () {
|
2023-03-24 15:32:28 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
// Stub this method to prevent unnecessary subscriptions to domain events
|
|
|
|
sinon.stub(DomainEvents, 'subscribe');
|
|
|
|
});
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2022-01-27 13:57:51 +03:00
|
|
|
it('Creates a threshold based on config', async function () {
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getImportTriggerThreshold: () => 2,
|
2023-03-21 21:00:14 +03:00
|
|
|
eventRepository: {
|
|
|
|
getSignupEvents: async () => ({
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-01-27 13:57:51 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = await trigger.getImportThreshold();
|
|
|
|
result.should.eql(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Increases the import threshold to the number of members', async function () {
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getImportTriggerThreshold: () => 2,
|
2023-03-21 21:00:14 +03:00
|
|
|
eventRepository: {
|
|
|
|
getSignupEvents: async () => ({
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2022-01-27 13:57:51 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = await trigger.getImportThreshold();
|
|
|
|
result.should.eql(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not check members count when config threshold is infinite', async function () {
|
|
|
|
const membersStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getImportTriggerThreshold: () => Infinity,
|
2023-03-21 21:00:14 +03:00
|
|
|
eventRepository: {
|
|
|
|
getSignupEvents: membersStub
|
2022-01-27 13:57:51 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const result = await trigger.getImportThreshold();
|
|
|
|
result.should.eql(Infinity);
|
|
|
|
membersStub.callCount.should.eql(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Email verification flow', function () {
|
2023-03-24 15:32:28 +03:00
|
|
|
let domainEventsStub;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
domainEventsStub = sinon.stub(DomainEvents, 'subscribe');
|
|
|
|
});
|
|
|
|
afterEach(function () {
|
|
|
|
sinon.restore();
|
|
|
|
});
|
|
|
|
|
2022-01-27 13:57:51 +03:00
|
|
|
it('Triggers verification process', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub
|
|
|
|
});
|
|
|
|
|
2022-08-25 04:47:59 +03:00
|
|
|
const result = await trigger._startVerificationProcess({
|
|
|
|
amount: 10,
|
2022-01-27 13:57:51 +03:00
|
|
|
throwOnTrigger: false
|
|
|
|
});
|
|
|
|
|
|
|
|
result.needsVerification.should.eql(true);
|
|
|
|
emailStub.callCount.should.eql(1);
|
|
|
|
settingsStub.callCount.should.eql(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not trigger verification when already verified', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => true,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub
|
|
|
|
});
|
|
|
|
|
2022-08-25 04:47:59 +03:00
|
|
|
const result = await trigger._startVerificationProcess({
|
|
|
|
amount: 10,
|
2022-01-27 13:57:51 +03:00
|
|
|
throwOnTrigger: false
|
|
|
|
});
|
|
|
|
|
|
|
|
result.needsVerification.should.eql(false);
|
|
|
|
emailStub.callCount.should.eql(0);
|
|
|
|
settingsStub.callCount.should.eql(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Does not trigger verification when already in progress', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => true,
|
|
|
|
sendVerificationEmail: emailStub
|
|
|
|
});
|
|
|
|
|
2022-08-25 04:47:59 +03:00
|
|
|
const result = await trigger._startVerificationProcess({
|
|
|
|
amount: 10,
|
2022-01-27 13:57:51 +03:00
|
|
|
throwOnTrigger: false
|
|
|
|
});
|
|
|
|
|
|
|
|
result.needsVerification.should.eql(false);
|
|
|
|
emailStub.callCount.should.eql(0);
|
|
|
|
settingsStub.callCount.should.eql(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Throws when `throwsOnTrigger` is true', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub
|
|
|
|
});
|
|
|
|
|
2022-08-25 04:47:59 +03:00
|
|
|
await trigger._startVerificationProcess({
|
|
|
|
amount: 10,
|
2022-01-27 13:57:51 +03:00
|
|
|
throwOnTrigger: true
|
|
|
|
}).should.be.rejected();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Sends a message containing the number of members imported', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub
|
|
|
|
});
|
|
|
|
|
2022-08-25 04:47:59 +03:00
|
|
|
await trigger._startVerificationProcess({
|
|
|
|
amount: 10,
|
2022-01-27 13:57:51 +03:00
|
|
|
throwOnTrigger: false
|
|
|
|
});
|
|
|
|
|
|
|
|
emailStub.lastCall.firstArg.should.eql({
|
|
|
|
subject: 'Email needs verification',
|
2022-08-25 10:38:19 +03:00
|
|
|
message: 'Email verification needed for site: {siteUrl}, has imported: {amountTriggered} members in the last 30 days.',
|
2022-08-25 05:43:46 +03:00
|
|
|
amountTriggered: 10
|
2022-01-27 13:57:51 +03:00
|
|
|
});
|
|
|
|
});
|
2022-02-03 18:02:33 +03:00
|
|
|
|
|
|
|
it('Triggers when a number of API events are dispatched', async function () {
|
2023-03-24 15:32:28 +03:00
|
|
|
// We need to use the real event repository here to test event handling
|
|
|
|
domainEventsStub.restore();
|
2022-02-03 18:02:33 +03:00
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-02-03 18:02:33 +03:00
|
|
|
}
|
|
|
|
});
|
2022-02-04 15:03:59 +03:00
|
|
|
|
2022-02-03 18:02:33 +03:00
|
|
|
new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getApiTriggerThreshold: () => 2,
|
2022-02-03 18:02:33 +03:00
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
2022-11-18 17:05:15 +03:00
|
|
|
getSignupEvents: eventStub
|
2022-02-03 18:02:33 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-06 08:50:27 +03:00
|
|
|
DomainEvents.dispatch(MemberCreatedEvent.create({
|
2022-02-03 18:02:33 +03:00
|
|
|
memberId: 'hello!',
|
|
|
|
source: 'api'
|
|
|
|
}, new Date()));
|
|
|
|
|
|
|
|
eventStub.callCount.should.eql(1);
|
2022-11-01 07:31:49 +03:00
|
|
|
eventStub.lastCall.lastArg.should.have.property('source');
|
|
|
|
eventStub.lastCall.lastArg.source.should.eql('api');
|
|
|
|
eventStub.lastCall.lastArg.should.have.property('created_at');
|
|
|
|
eventStub.lastCall.lastArg.created_at.should.have.property('$gt');
|
|
|
|
eventStub.lastCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/);
|
2022-02-03 18:02:33 +03:00
|
|
|
});
|
2022-04-13 19:35:24 +03:00
|
|
|
|
|
|
|
it('Triggers when a number of members are imported', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-04-13 19:35:24 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getImportTriggerThreshold: () => 2,
|
2022-04-13 19:35:24 +03:00
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
2022-11-18 17:05:15 +03:00
|
|
|
getSignupEvents: eventStub
|
2022-04-13 19:35:24 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await trigger.testImportThreshold();
|
|
|
|
|
2023-03-21 21:00:14 +03:00
|
|
|
eventStub.callCount.should.eql(2);
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('source');
|
|
|
|
eventStub.firstCall.lastArg.source.should.eql('import');
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('created_at');
|
|
|
|
eventStub.firstCall.lastArg.created_at.should.have.property('$gt');
|
|
|
|
eventStub.firstCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/);
|
2022-04-13 19:35:24 +03:00
|
|
|
|
|
|
|
emailStub.callCount.should.eql(1);
|
|
|
|
emailStub.lastCall.firstArg.should.eql({
|
|
|
|
subject: 'Email needs verification',
|
2022-08-25 10:38:19 +03:00
|
|
|
message: 'Email verification needed for site: {siteUrl}, has imported: {amountTriggered} members in the last 30 days.',
|
2022-08-25 05:43:46 +03:00
|
|
|
amountTriggered: 10
|
2022-04-13 19:35:24 +03:00
|
|
|
});
|
|
|
|
});
|
2022-08-25 09:26:26 +03:00
|
|
|
|
2023-01-04 13:22:12 +03:00
|
|
|
it('checkVerificationRequired also checks import', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
let isVerificationRequired = false;
|
|
|
|
const isVerificationRequiredStub = sinon.stub().callsFake(() => {
|
|
|
|
return isVerificationRequired;
|
|
|
|
});
|
|
|
|
const settingsStub = sinon.stub().callsFake(() => {
|
|
|
|
isVerificationRequired = true;
|
|
|
|
return Promise.resolve();
|
|
|
|
});
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-01-04 13:22:12 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
getImportTriggerThreshold: () => 2,
|
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: isVerificationRequiredStub,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
|
|
|
getSignupEvents: eventStub
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(await trigger.checkVerificationRequired(), true);
|
|
|
|
sinon.assert.calledOnce(emailStub);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('testImportThreshold does not calculate anything if already verified', async function () {
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
getImportTriggerThreshold: () => 2,
|
|
|
|
isVerified: () => true
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(await trigger.testImportThreshold(), undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('testImportThreshold does not calculate anything if already pending', async function () {
|
|
|
|
const trigger = new VerificationTrigger({
|
|
|
|
getImportTriggerThreshold: () => 2,
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => true
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(await trigger.testImportThreshold(), undefined);
|
|
|
|
});
|
|
|
|
|
2022-08-25 09:26:26 +03:00
|
|
|
it('Triggers when a number of members are added from Admin', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-08-25 09:26:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getAdminTriggerThreshold: () => 2,
|
2022-08-25 09:26:26 +03:00
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
2022-11-18 17:05:15 +03:00
|
|
|
getSignupEvents: eventStub
|
2022-08-25 09:26:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-06 08:50:27 +03:00
|
|
|
await trigger._handleMemberCreatedEvent({
|
2022-08-25 09:26:26 +03:00
|
|
|
data: {
|
|
|
|
source: 'admin'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-21 21:00:14 +03:00
|
|
|
eventStub.callCount.should.eql(2);
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('source');
|
|
|
|
eventStub.firstCall.lastArg.source.should.eql('admin');
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('created_at');
|
|
|
|
eventStub.firstCall.lastArg.created_at.should.have.property('$gt');
|
|
|
|
eventStub.firstCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/);
|
2022-08-25 09:26:26 +03:00
|
|
|
|
|
|
|
emailStub.callCount.should.eql(1);
|
|
|
|
emailStub.lastCall.firstArg.should.eql({
|
|
|
|
subject: 'Email needs verification',
|
2022-08-25 10:38:19 +03:00
|
|
|
message: 'Email verification needed for site: {siteUrl} has added: {amountTriggered} members through the Admin client in the last 30 days.',
|
2022-08-25 09:26:26 +03:00
|
|
|
amountTriggered: 10
|
|
|
|
});
|
|
|
|
});
|
2023-01-04 13:22:12 +03:00
|
|
|
|
2022-08-25 09:26:26 +03:00
|
|
|
it('Triggers when a number of members are added from API', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-08-25 09:26:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getAdminTriggerThreshold: () => 2,
|
|
|
|
getApiTriggerThreshold: () => 2,
|
2022-08-25 09:26:26 +03:00
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
2022-11-18 17:05:15 +03:00
|
|
|
getSignupEvents: eventStub
|
2022-08-25 09:26:26 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-10-06 08:50:27 +03:00
|
|
|
await trigger._handleMemberCreatedEvent({
|
2022-08-25 09:26:26 +03:00
|
|
|
data: {
|
|
|
|
source: 'api'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-03-21 21:00:14 +03:00
|
|
|
eventStub.callCount.should.eql(2);
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('source');
|
|
|
|
eventStub.firstCall.lastArg.source.should.eql('api');
|
|
|
|
eventStub.firstCall.lastArg.should.have.property('created_at');
|
|
|
|
eventStub.firstCall.lastArg.created_at.should.have.property('$gt');
|
|
|
|
eventStub.firstCall.lastArg.created_at.$gt.should.match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/);
|
2022-08-25 09:26:26 +03:00
|
|
|
|
|
|
|
emailStub.callCount.should.eql(1);
|
|
|
|
emailStub.lastCall.firstArg.should.eql({
|
|
|
|
subject: 'Email needs verification',
|
2022-08-25 10:38:19 +03:00
|
|
|
message: 'Email verification needed for site: {siteUrl} has added: {amountTriggered} members through the API in the last 30 days.',
|
2022-08-25 09:26:26 +03:00
|
|
|
amountTriggered: 10
|
|
|
|
});
|
2022-08-25 05:43:46 +03:00
|
|
|
});
|
2022-07-26 12:35:48 +03:00
|
|
|
|
|
|
|
it('Does not fetch events and trigger when threshold is Infinity', async function () {
|
|
|
|
const emailStub = sinon.stub().resolves(null);
|
|
|
|
const settingsStub = sinon.stub().resolves(null);
|
2023-03-21 21:00:14 +03:00
|
|
|
const eventStub = sinon.stub().callsFake(async (_unused, {source}) => {
|
|
|
|
if (source === 'member') {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 15
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
meta: {
|
|
|
|
pagination: {
|
|
|
|
total: 10
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2022-07-26 12:35:48 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const trigger = new VerificationTrigger({
|
2023-01-04 13:22:12 +03:00
|
|
|
getImportTriggerThreshold: () => Infinity,
|
2022-07-26 12:35:48 +03:00
|
|
|
Settings: {
|
|
|
|
edit: settingsStub
|
|
|
|
},
|
|
|
|
isVerified: () => false,
|
|
|
|
isVerificationRequired: () => false,
|
|
|
|
sendVerificationEmail: emailStub,
|
|
|
|
eventRepository: {
|
2022-11-18 17:05:15 +03:00
|
|
|
getSignupEvents: eventStub
|
2022-07-26 12:35:48 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
await trigger.testImportThreshold();
|
|
|
|
|
|
|
|
// We shouldn't be fetching the events if the threshold is Infinity
|
|
|
|
eventStub.callCount.should.eql(0);
|
|
|
|
|
2022-08-25 04:41:45 +03:00
|
|
|
// We shouldn't be sending emails if the threshold is Infinity
|
2022-07-26 12:35:48 +03:00
|
|
|
emailStub.callCount.should.eql(0);
|
|
|
|
});
|
2022-02-04 15:03:59 +03:00
|
|
|
});
|