|
|
@@ -1,14 +1,3 @@
|
|
|
-/* eslint-disable
|
|
|
- max-len,
|
|
|
- no-return-assign,
|
|
|
-*/
|
|
|
-// TODO: This file was created by bulk-decaffeinate.
|
|
|
-// Fix any style issues and re-enable lint.
|
|
|
-/*
|
|
|
- * decaffeinate suggestions:
|
|
|
- * DS102: Remove unnecessary code created because of implicit returns
|
|
|
- * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
- */
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
const { expect } = require('chai')
|
|
|
const sinon = require('sinon')
|
|
|
@@ -19,7 +8,12 @@ const modulePath = require('path').join(
|
|
|
|
|
|
describe('InstitutionsGetter', function () {
|
|
|
beforeEach(function () {
|
|
|
- this.UserGetter = { getUserFullEmails: sinon.stub() }
|
|
|
+ this.UserGetter = {
|
|
|
+ getUserFullEmails: sinon.stub(),
|
|
|
+ promises: {
|
|
|
+ getUserFullEmails: sinon.stub(),
|
|
|
+ },
|
|
|
+ }
|
|
|
this.InstitutionsGetter = SandboxedModule.require(modulePath, {
|
|
|
requires: {
|
|
|
'../User/UserGetter': this.UserGetter,
|
|
|
@@ -28,60 +22,72 @@ describe('InstitutionsGetter', function () {
|
|
|
},
|
|
|
})
|
|
|
|
|
|
- return (this.userId = '12345abcde')
|
|
|
- })
|
|
|
-
|
|
|
- describe('getConfirmedInstitutions', function () {
|
|
|
- it('filters unconfirmed affiliations', function (done) {
|
|
|
- this.userEmails = [
|
|
|
- {
|
|
|
- confirmedAt: null,
|
|
|
- affiliation: { institution: { id: 123, confirmed: true } },
|
|
|
- },
|
|
|
- {
|
|
|
- confirmedAt: new Date(),
|
|
|
- affiliation: { institution: { id: 456, confirmed: true } },
|
|
|
+ this.userId = '12345abcde'
|
|
|
+ this.confirmedAffiliation = {
|
|
|
+ confirmedAt: new Date(),
|
|
|
+ affiliation: {
|
|
|
+ institution: { id: 456, confirmed: true },
|
|
|
+ pastReconfirmDate: false,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ this.confirmedAffiliationPastReconfirmation = {
|
|
|
+ confirmedAt: new Date('2000-01-01'),
|
|
|
+ affiliation: {
|
|
|
+ institution: { id: 135, confirmed: true },
|
|
|
+ pastReconfirmDate: true,
|
|
|
+ },
|
|
|
+ }
|
|
|
+ this.userEmails = [
|
|
|
+ {
|
|
|
+ confirmedAt: null,
|
|
|
+ affiliation: {
|
|
|
+ institution: { id: 123, confirmed: true, pastReconfirmDate: false },
|
|
|
},
|
|
|
- { confirmedAt: new Date(), affiliation: null },
|
|
|
- { confirmedAt: new Date(), affiliation: { institution: null } },
|
|
|
- {
|
|
|
- confirmedAt: new Date(),
|
|
|
- affiliation: { institution: { id: 789, confirmed: false } },
|
|
|
+ },
|
|
|
+ this.confirmedAffiliation,
|
|
|
+ this.confirmedAffiliation,
|
|
|
+ this.confirmedAffiliationPastReconfirmation,
|
|
|
+ { confirmedAt: new Date(), affiliation: null, pastReconfirmDate: false },
|
|
|
+ {
|
|
|
+ confirmedAt: new Date(),
|
|
|
+ affiliation: { institution: null, pastReconfirmDate: false },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ confirmedAt: new Date(),
|
|
|
+ affiliation: {
|
|
|
+ institution: { id: 789, confirmed: false, pastReconfirmDate: false },
|
|
|
},
|
|
|
- ]
|
|
|
- this.UserGetter.getUserFullEmails.yields(null, this.userEmails)
|
|
|
- return this.InstitutionsGetter.getConfirmedInstitutions(
|
|
|
- this.userId,
|
|
|
- (error, institutions) => {
|
|
|
- expect(error).to.not.exist
|
|
|
- institutions.length.should.equal(1)
|
|
|
- institutions[0].id.should.equal(456)
|
|
|
- return done()
|
|
|
- }
|
|
|
- )
|
|
|
- })
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ })
|
|
|
|
|
|
- it('should handle empty response', function (done) {
|
|
|
- this.UserGetter.getUserFullEmails.yields(null, [])
|
|
|
- return this.InstitutionsGetter.getConfirmedInstitutions(
|
|
|
- this.userId,
|
|
|
- (error, institutions) => {
|
|
|
- expect(error).to.not.exist
|
|
|
- institutions.length.should.equal(0)
|
|
|
- return done()
|
|
|
- }
|
|
|
+ describe('getCurrentInstitutionIds', function () {
|
|
|
+ it('filters unconfirmed affiliations, those past reconfirmation, and returns only 1 result per institution', async function () {
|
|
|
+ this.UserGetter.promises.getUserFullEmails.resolves(this.userEmails)
|
|
|
+ const institutions = await this.InstitutionsGetter.promises.getCurrentInstitutionIds(
|
|
|
+ this.userId
|
|
|
)
|
|
|
+ expect(institutions.length).to.equal(1)
|
|
|
+ expect(institutions[0]).to.equal(456)
|
|
|
})
|
|
|
-
|
|
|
- it('should handle error', function (done) {
|
|
|
- this.UserGetter.getUserFullEmails.yields(new Error('Nope'))
|
|
|
- return this.InstitutionsGetter.getConfirmedInstitutions(
|
|
|
- this.userId,
|
|
|
- (error, institutions) => {
|
|
|
- expect(error).to.exist
|
|
|
- return done()
|
|
|
- }
|
|
|
+ it('handles empty response', async function () {
|
|
|
+ this.UserGetter.promises.getUserFullEmails.resolves([])
|
|
|
+ const institutions = await this.InstitutionsGetter.promises.getCurrentInstitutionIds(
|
|
|
+ this.userId
|
|
|
)
|
|
|
+ expect(institutions).to.deep.equal([])
|
|
|
+ })
|
|
|
+ it('handles errors', async function () {
|
|
|
+ this.UserGetter.promises.getUserFullEmails.rejects(new Error('oops'))
|
|
|
+ let e
|
|
|
+ try {
|
|
|
+ await this.InstitutionsGetter.promises.getCurrentInstitutionIds(
|
|
|
+ this.userId
|
|
|
+ )
|
|
|
+ } catch (error) {
|
|
|
+ e = error
|
|
|
+ }
|
|
|
+ expect(e.message).to.equal('oops')
|
|
|
})
|
|
|
})
|
|
|
})
|