|
@@ -4,12 +4,6 @@ const { ObjectId } = require('mongodb-legacy')
|
|
|
|
|
|
|
|
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectHelper.js'
|
|
const MODULE_PATH = '../../../../app/src/Features/Project/ProjectHelper.js'
|
|
|
|
|
|
|
|
-function _mapToAllowed(images) {
|
|
|
|
|
- return images.map(image => {
|
|
|
|
|
- return { imageName: image.imageName, allowed: image.allowed }
|
|
|
|
|
- })
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
describe('ProjectHelper', function () {
|
|
describe('ProjectHelper', function () {
|
|
|
beforeEach(function () {
|
|
beforeEach(function () {
|
|
|
this.project = {
|
|
this.project = {
|
|
@@ -20,8 +14,6 @@ describe('ProjectHelper', function () {
|
|
|
_id: '588f3ddae8ebc1bac07c9fa4',
|
|
_id: '588f3ddae8ebc1bac07c9fa4',
|
|
|
first_name: 'bjkdsjfk',
|
|
first_name: 'bjkdsjfk',
|
|
|
features: {},
|
|
features: {},
|
|
|
- labsProgram: true,
|
|
|
|
|
- labsExperiments: ['monthly-texlive'],
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.adminUser = {
|
|
this.adminUser = {
|
|
@@ -40,11 +32,6 @@ describe('ProjectHelper', function () {
|
|
|
imageDesc: 'TeX Live 2020',
|
|
imageDesc: 'TeX Live 2020',
|
|
|
alphaOnly: true,
|
|
alphaOnly: true,
|
|
|
},
|
|
},
|
|
|
- {
|
|
|
|
|
- imageName: 'texlive-full:2021.1',
|
|
|
|
|
- imageDesc: 'TeX Live 2021',
|
|
|
|
|
- monthlyExperimental: true,
|
|
|
|
|
- },
|
|
|
|
|
],
|
|
],
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -141,58 +128,31 @@ describe('ProjectHelper', function () {
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('getAllowedImagesForUser', function () {
|
|
describe('getAllowedImagesForUser', function () {
|
|
|
- it('marks alpha only images as not allowed when the user is anonymous', function () {
|
|
|
|
|
- const images = this.ProjectHelper.getAllowedImagesForUser(null)
|
|
|
|
|
- const imageNames = _mapToAllowed(images)
|
|
|
|
|
- expect(imageNames).to.deep.equal([
|
|
|
|
|
- { imageName: 'texlive-full:2018.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2019.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2020.1', allowed: false },
|
|
|
|
|
- { imageName: 'texlive-full:2021.1', allowed: false },
|
|
|
|
|
- ])
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('marks monthly labs images as not allowed when the user is anonymous', function () {
|
|
|
|
|
|
|
+ it('filters out alpha-only images when the user is anonymous', function () {
|
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(null)
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(null)
|
|
|
- const imageNames = _mapToAllowed(images)
|
|
|
|
|
- expect(imageNames).to.deep.equal([
|
|
|
|
|
- { imageName: 'texlive-full:2018.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2019.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2020.1', allowed: false },
|
|
|
|
|
- { imageName: 'texlive-full:2021.1', allowed: false },
|
|
|
|
|
- ])
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- it('marks monthly labs images as allowed when the user is enrolled', function () {
|
|
|
|
|
- const images = this.ProjectHelper.getAllowedImagesForUser(this.user)
|
|
|
|
|
- const imageNames = _mapToAllowed(images)
|
|
|
|
|
|
|
+ const imageNames = images.map(image => image.imageName)
|
|
|
expect(imageNames).to.deep.equal([
|
|
expect(imageNames).to.deep.equal([
|
|
|
- { imageName: 'texlive-full:2018.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2019.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2020.1', allowed: false },
|
|
|
|
|
- { imageName: 'texlive-full:2021.1', allowed: true },
|
|
|
|
|
|
|
+ 'texlive-full:2018.1',
|
|
|
|
|
+ 'texlive-full:2019.1',
|
|
|
])
|
|
])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
- it('marks alpha only images as not allowed when when the user is not admin', function () {
|
|
|
|
|
|
|
+ it('filters out alpha-only images when the user is not admin', function () {
|
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(this.user)
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(this.user)
|
|
|
- const imageNames = _mapToAllowed(images)
|
|
|
|
|
|
|
+ const imageNames = images.map(image => image.imageName)
|
|
|
expect(imageNames).to.deep.equal([
|
|
expect(imageNames).to.deep.equal([
|
|
|
- { imageName: 'texlive-full:2018.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2019.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2020.1', allowed: false },
|
|
|
|
|
- { imageName: 'texlive-full:2021.1', allowed: true },
|
|
|
|
|
|
|
+ 'texlive-full:2018.1',
|
|
|
|
|
+ 'texlive-full:2019.1',
|
|
|
])
|
|
])
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('returns all images when the user is admin', function () {
|
|
it('returns all images when the user is admin', function () {
|
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(this.adminUser)
|
|
const images = this.ProjectHelper.getAllowedImagesForUser(this.adminUser)
|
|
|
- const imageNames = _mapToAllowed(images)
|
|
|
|
|
|
|
+ const imageNames = images.map(image => image.imageName)
|
|
|
expect(imageNames).to.deep.equal([
|
|
expect(imageNames).to.deep.equal([
|
|
|
- { imageName: 'texlive-full:2018.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2019.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2020.1', allowed: true },
|
|
|
|
|
- { imageName: 'texlive-full:2021.1', allowed: false },
|
|
|
|
|
|
|
+ 'texlive-full:2018.1',
|
|
|
|
|
+ 'texlive-full:2019.1',
|
|
|
|
|
+ 'texlive-full:2020.1',
|
|
|
])
|
|
])
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|