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