2019-05-29 05:21:06 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Subscription/SubscriptionLocator'
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('Subscription Locator Tests', function () {
|
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user = { _id: '5208dd34438842e2db333333' }
|
|
|
|
this.subscription = { hello: 'world' }
|
|
|
|
this.Subscription = {
|
|
|
|
findOne: sinon.stub(),
|
2021-04-27 03:52:58 -04:00
|
|
|
find: sinon.stub(),
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
2019-09-10 10:03:29 -04:00
|
|
|
this.DeletedSubscription = {
|
|
|
|
findOne: sinon.stub().yields(),
|
2021-04-27 03:52:58 -04:00
|
|
|
find: sinon.stub().yields(),
|
2019-09-10 10:03:29 -04:00
|
|
|
}
|
2022-05-17 06:10:19 -04:00
|
|
|
this.SubscriptionLocator = SandboxedModule.require(modulePath, {
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
2020-11-27 08:11:12 -05:00
|
|
|
'./GroupPlansData': {},
|
2019-05-29 05:21:06 -04:00
|
|
|
'../../models/Subscription': {
|
2021-04-27 03:52:58 -04:00
|
|
|
Subscription: this.Subscription,
|
2019-05-29 05:21:06 -04:00
|
|
|
},
|
2019-09-10 10:03:29 -04:00
|
|
|
'../../models/DeletedSubscription': {
|
2021-04-27 03:52:58 -04:00
|
|
|
DeletedSubscription: this.DeletedSubscription,
|
|
|
|
},
|
|
|
|
},
|
2022-05-17 06:10:19 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('finding users subscription', function () {
|
|
|
|
it('should send the users features', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Subscription.findOne.callsArgWith(1, null, this.subscription)
|
2022-05-17 06:10:19 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(err, subscription) => {
|
2022-05-17 06:10:19 -04:00
|
|
|
if (err) return done(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Subscription.findOne
|
|
|
|
.calledWith({ admin_id: this.user._id })
|
|
|
|
.should.equal(true)
|
|
|
|
subscription.should.equal(this.subscription)
|
2022-05-17 06:10:19 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should error if not found', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Subscription.findOne.callsArgWith(1, 'not found')
|
2022-05-17 06:10:19 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user,
|
|
|
|
(err, subscription) => {
|
|
|
|
err.should.exist
|
2022-05-17 06:10:19 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should take a user id rather than the user object', function (done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Subscription.findOne.callsArgWith(1, null, this.subscription)
|
2022-05-17 06:10:19 -04:00
|
|
|
this.SubscriptionLocator.getUsersSubscription(
|
2019-05-29 05:21:06 -04:00
|
|
|
this.user._id,
|
|
|
|
(err, subscription) => {
|
2022-05-17 06:10:19 -04:00
|
|
|
if (err) return done(err)
|
2019-05-29 05:21:06 -04:00
|
|
|
this.Subscription.findOne
|
|
|
|
.calledWith({ admin_id: this.user._id })
|
|
|
|
.should.equal(true)
|
|
|
|
subscription.should.equal(this.subscription)
|
2022-05-17 06:10:19 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|