| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- const SandboxedModule = require('sandboxed-module')
- require('chai').should()
- const sinon = require('sinon')
- const modulePath = require('path').join(
- __dirname,
- '../../../../app/src/Features/Notifications/NotificationsBuilder.js'
- )
- describe('NotificationsBuilder', function() {
- const userId = '123nd3ijdks'
- describe('ipMatcherAffiliation', function() {
- beforeEach(function() {
- this.handler = { createNotification: sinon.stub().callsArgWith(6) }
- this.settings = { apis: { v1: { url: 'v1.url', user: '', pass: '' } } }
- this.request = sinon.stub()
- this.controller = SandboxedModule.require(modulePath, {
- globals: {
- console: console
- },
- requires: {
- './NotificationsHandler': this.handler,
- 'settings-sharelatex': this.settings,
- request: this.request,
- 'logger-sharelatex': {
- log() {},
- err() {}
- }
- }
- })
- })
- describe('with portal and with SSO', function() {
- beforeEach(function() {
- this.body = {
- id: 1,
- name: 'stanford',
- enrolment_ad_html: 'v1 ad content',
- is_university: true,
- portal_slug: null,
- sso_enabled: false
- }
- this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
- })
- it('should call v1 and create affiliation notifications', function(done) {
- const ip = '192.168.0.1'
- this.controller.ipMatcherAffiliation(userId).create(ip, callback => {
- this.request.calledOnce.should.equal(true)
- const expectedOpts = {
- institutionId: this.body.id,
- university_name: this.body.name,
- content: this.body.enrolment_ad_html,
- ssoEnabled: false,
- portalPath: undefined
- }
- this.handler.createNotification
- .calledWith(
- userId,
- `ip-matched-affiliation-${this.body.id}`,
- 'notification_ip_matched_affiliation',
- expectedOpts
- )
- .should.equal(true)
- done()
- })
- })
- })
- describe('without portal and without SSO', function() {
- beforeEach(function() {
- this.body = {
- id: 1,
- name: 'stanford',
- enrolment_ad_html: 'v1 ad content',
- is_university: true,
- portal_slug: 'stanford',
- sso_enabled: true
- }
- this.request.callsArgWith(1, null, { statusCode: 200 }, this.body)
- })
- it('should call v1 and create affiliation notifications', function(done) {
- const ip = '192.168.0.1'
- this.controller.ipMatcherAffiliation(userId).create(ip, callback => {
- this.request.calledOnce.should.equal(true)
- const expectedOpts = {
- institutionId: this.body.id,
- university_name: this.body.name,
- content: this.body.enrolment_ad_html,
- ssoEnabled: true,
- portalPath: '/edu/stanford'
- }
- this.handler.createNotification
- .calledWith(
- userId,
- `ip-matched-affiliation-${this.body.id}`,
- 'notification_ip_matched_affiliation',
- expectedOpts
- )
- .should.equal(true)
- done()
- })
- })
- })
- })
- })
|