|
@@ -102,13 +102,17 @@ describe('UserCreator', function () {
|
|
|
ctx.UserCreator = (await import(modulePath)).default
|
|
ctx.UserCreator = (await import(modulePath)).default
|
|
|
|
|
|
|
|
ctx.email = 'bob.oswald@gmail.com'
|
|
ctx.email = 'bob.oswald@gmail.com'
|
|
|
|
|
+ ctx.attributes = {
|
|
|
|
|
+ email: ctx.email,
|
|
|
|
|
+ analyticsId: '8055c676-bcc7-4e64-a66f-8069f9a0bd92',
|
|
|
|
|
+ }
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('createNewUser', function () {
|
|
describe('createNewUser', function () {
|
|
|
describe('with callbacks', function () {
|
|
describe('with callbacks', function () {
|
|
|
it('should take the opts and put them in the model', async function (ctx) {
|
|
it('should take the opts and put them in the model', async function (ctx) {
|
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
holdingAccount: true,
|
|
holdingAccount: true,
|
|
|
})
|
|
})
|
|
|
assert.equal(user.email, ctx.email)
|
|
assert.equal(user.email, ctx.email)
|
|
@@ -118,7 +122,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should use the start of the email if the first name is empty string', async function (ctx) {
|
|
it('should use the start of the email if the first name is empty string', async function (ctx) {
|
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
holdingAccount: true,
|
|
holdingAccount: true,
|
|
|
first_name: '',
|
|
first_name: '',
|
|
|
})
|
|
})
|
|
@@ -129,7 +133,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should use the first name if passed', async function (ctx) {
|
|
it('should use the first name if passed', async function (ctx) {
|
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
holdingAccount: true,
|
|
holdingAccount: true,
|
|
|
first_name: 'fiiirstname',
|
|
first_name: 'fiiirstname',
|
|
|
})
|
|
})
|
|
@@ -140,7 +144,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should use the last name if passed', async function (ctx) {
|
|
it('should use the last name if passed', async function (ctx) {
|
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
holdingAccount: true,
|
|
holdingAccount: true,
|
|
|
last_name: 'lastNammmmeee',
|
|
last_name: 'lastNammmmeee',
|
|
|
})
|
|
})
|
|
@@ -150,9 +154,9 @@ describe('UserCreator', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should set emails attribute', async function (ctx) {
|
|
it('should set emails attribute', async function (ctx) {
|
|
|
- const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
|
|
- email: ctx.email,
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ const user = await ctx.UserCreator.promises.createNewUser(
|
|
|
|
|
+ ctx.attributes
|
|
|
|
|
+ )
|
|
|
user.email.should.equal(ctx.email)
|
|
user.email.should.equal(ctx.email)
|
|
|
user.emails.length.should.equal(1)
|
|
user.emails.length.should.equal(1)
|
|
|
user.emails[0].email.should.equal(ctx.email)
|
|
user.emails[0].email.should.equal(ctx.email)
|
|
@@ -161,9 +165,8 @@ describe('UserCreator', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('with affiliations feature', function () {
|
|
describe('with affiliations feature', function () {
|
|
|
- let attributes, user
|
|
|
|
|
|
|
+ let user
|
|
|
beforeEach(function (ctx) {
|
|
beforeEach(function (ctx) {
|
|
|
- attributes = { email: ctx.email }
|
|
|
|
|
ctx.Features.hasFeature = sinon
|
|
ctx.Features.hasFeature = sinon
|
|
|
.stub()
|
|
.stub()
|
|
|
.withArgs('affiliations')
|
|
.withArgs('affiliations')
|
|
@@ -172,7 +175,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
describe('when v1 affiliations API does not return an error', function () {
|
|
describe('when v1 affiliations API does not return an error', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
beforeEach(async function (ctx) {
|
|
|
- user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ user = await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should flag that affiliation is unchecked', function () {
|
|
it('should flag that affiliation is unchecked', function () {
|
|
@@ -198,7 +201,7 @@ describe('UserCreator', function () {
|
|
|
describe('when v1 affiliations API does return an error', function () {
|
|
describe('when v1 affiliations API does return an error', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
beforeEach(async function (ctx) {
|
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
|
|
- user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ user = await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should flag that affiliation is unchecked', function () {
|
|
it('should flag that affiliation is unchecked', function () {
|
|
@@ -228,7 +231,7 @@ describe('UserCreator', function () {
|
|
|
describe('when v1 affiliations API returns an error and requireAffiliation=true', function () {
|
|
describe('when v1 affiliations API returns an error and requireAffiliation=true', function () {
|
|
|
beforeEach(async function (ctx) {
|
|
beforeEach(async function (ctx) {
|
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser.rejects()
|
|
|
- user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ user = await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should flag that affiliation is unchecked', function () {
|
|
it('should flag that affiliation is unchecked', function () {
|
|
@@ -257,8 +260,7 @@ describe('UserCreator', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not add affiliation when without affiliation feature', async function (ctx) {
|
|
it('should not add affiliation when without affiliation feature', async function (ctx) {
|
|
|
- const attributes = { email: ctx.email }
|
|
|
|
|
- await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
sinon.assert.notCalled(
|
|
sinon.assert.notCalled(
|
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
|
)
|
|
)
|
|
@@ -268,7 +270,7 @@ describe('UserCreator', function () {
|
|
|
describe('with promises', function () {
|
|
describe('with promises', function () {
|
|
|
it('should take the opts and put them in the model', async function (ctx) {
|
|
it('should take the opts and put them in the model', async function (ctx) {
|
|
|
const opts = {
|
|
const opts = {
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
holdingAccount: true,
|
|
holdingAccount: true,
|
|
|
}
|
|
}
|
|
|
const user = await ctx.UserCreator.promises.createNewUser(opts)
|
|
const user = await ctx.UserCreator.promises.createNewUser(opts)
|
|
@@ -282,8 +284,9 @@ describe('UserCreator', function () {
|
|
|
.stub()
|
|
.stub()
|
|
|
.withArgs('affiliations')
|
|
.withArgs('affiliations')
|
|
|
.returns(true)
|
|
.returns(true)
|
|
|
- const attributes = { email: ctx.email }
|
|
|
|
|
- const user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ const user = await ctx.UserCreator.promises.createNewUser(
|
|
|
|
|
+ ctx.attributes
|
|
|
|
|
+ )
|
|
|
sinon.assert.calledOnce(
|
|
sinon.assert.calledOnce(
|
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
|
)
|
|
)
|
|
@@ -296,8 +299,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should not add affiliation when without affiliation feature', async function (ctx) {
|
|
it('should not add affiliation when without affiliation feature', async function (ctx) {
|
|
|
ctx.Features.hasFeature = sinon.stub().returns(false)
|
|
ctx.Features.hasFeature = sinon.stub().returns(false)
|
|
|
- const attributes = { email: ctx.email }
|
|
|
|
|
- await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
sinon.assert.notCalled(
|
|
sinon.assert.notCalled(
|
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
ctx.UserUpdater.promises.addAffiliationForNewUser
|
|
|
)
|
|
)
|
|
@@ -305,7 +307,7 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should include SAML provider ID with email', async function (ctx) {
|
|
it('should include SAML provider ID with email', async function (ctx) {
|
|
|
const attributes = {
|
|
const attributes = {
|
|
|
- email: ctx.email,
|
|
|
|
|
|
|
+ ...ctx.attributes,
|
|
|
samlIdentifiers: [{ email: ctx.email, providerId: '1' }],
|
|
samlIdentifiers: [{ email: ctx.email, providerId: '1' }],
|
|
|
}
|
|
}
|
|
|
const user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
const user = await ctx.UserCreator.promises.createNewUser(attributes)
|
|
@@ -313,9 +315,9 @@ describe('UserCreator', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should fire an analytics event and user property on registration', async function (ctx) {
|
|
it('should fire an analytics event and user property on registration', async function (ctx) {
|
|
|
- const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
|
|
- email: ctx.email,
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ const user = await ctx.UserCreator.promises.createNewUser(
|
|
|
|
|
+ ctx.attributes
|
|
|
|
|
+ )
|
|
|
assert.equal(user.email, ctx.email)
|
|
assert.equal(user.email, ctx.email)
|
|
|
sinon.assert.calledWith(
|
|
sinon.assert.calledWith(
|
|
|
ctx.Analytics.recordEventForUserInBackground,
|
|
ctx.Analytics.recordEventForUserInBackground,
|
|
@@ -331,9 +333,9 @@ describe('UserCreator', function () {
|
|
|
|
|
|
|
|
it('should schedule post registration jobs on registration with saas feature', async function (ctx) {
|
|
it('should schedule post registration jobs on registration with saas feature', async function (ctx) {
|
|
|
ctx.Features.hasFeature = sinon.stub().withArgs('saas').returns(true)
|
|
ctx.Features.hasFeature = sinon.stub().withArgs('saas').returns(true)
|
|
|
- const user = await ctx.UserCreator.promises.createNewUser({
|
|
|
|
|
- email: ctx.email,
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ const user = await ctx.UserCreator.promises.createNewUser(
|
|
|
|
|
+ ctx.attributes
|
|
|
|
|
+ )
|
|
|
assert.equal(user.email, ctx.email)
|
|
assert.equal(user.email, ctx.email)
|
|
|
sinon.assert.calledWith(
|
|
sinon.assert.calledWith(
|
|
|
ctx.UserOnboardingEmailManager.scheduleOnboardingEmail,
|
|
ctx.UserOnboardingEmailManager.scheduleOnboardingEmail,
|
|
@@ -347,8 +349,7 @@ describe('UserCreator', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should not schedule post registration checks when without saas feature', async function (ctx) {
|
|
it('should not schedule post registration checks when without saas feature', async function (ctx) {
|
|
|
- const attributes = { email: ctx.email }
|
|
|
|
|
- await ctx.UserCreator.promises.createNewUser(attributes)
|
|
|
|
|
|
|
+ await ctx.UserCreator.promises.createNewUser(ctx.attributes)
|
|
|
sinon.assert.notCalled(
|
|
sinon.assert.notCalled(
|
|
|
ctx.UserOnboardingEmailManager.scheduleOnboardingEmail
|
|
ctx.UserOnboardingEmailManager.scheduleOnboardingEmail
|
|
|
)
|
|
)
|
|
@@ -357,6 +358,14 @@ describe('UserCreator', function () {
|
|
|
.schedulePostRegistrationAnalytics
|
|
.schedulePostRegistrationAnalytics
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
|
|
+
|
|
|
|
|
+ it('should throw without analyticsId', async function (ctx) {
|
|
|
|
|
+ await expect(
|
|
|
|
|
+ ctx.UserCreator.promises.createNewUser({ email: ctx.email })
|
|
|
|
|
+ ).to.eventually.be.rejectedWith(
|
|
|
|
|
+ /bug: attributes.analyticsId is missing/
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|