Skip to content

Commit

Permalink
removing calls to appdata
Browse files Browse the repository at this point in the history
  • Loading branch information
Matte22 committed Sep 17, 2024
1 parent 90e8c23 commit 5c90ec2
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 111 deletions.
12 changes: 9 additions & 3 deletions test/api/mocha/data/asset/assetPatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const expectations = require('./expectations.js')
const reference = require('../../referenceData.js')

describe('PATCH - Asset', function () {

before(async () => {
await utils.loadAppData()
})

after(async () => {
await utils.resetTestAsset()
Expand All @@ -23,11 +27,13 @@ describe('PATCH - Asset', function () {

describe(`iteration:${iteration.name}`, function () {
const distinct = expectations[iteration.name]

let testAsset = null
let scrapAsset = null
beforeEach(async function () {

this.timeout(4000)
await utils.resetTestAsset()
await utils.resetScrapAsset()
testAsset = await utils.resetTestAsset()
scrapAsset = await utils.resetScrapAsset()
})

describe(`updateAsset - /assets/{assetId}`, function () {
Expand Down
89 changes: 35 additions & 54 deletions test/api/mocha/data/collection/collectionDelete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ const utils = require('../../utils/testUtils')
const iterations = require('../../iterations')
const expectations = require('./expectations')
const reference = require('../../referenceData.js')
const requestBodies = require('./requestBodies')

describe('DELETE - Collection ', function () {

before(async function () {
this.timeout(4000)
await utils.uploadTestStigs()
})
let tempCollection = null

beforeEach(async function () {
this.timeout(4000)
await utils.loadAppData()
})
// before(async function () {
// await utils.loadAppData()
// })

for(const iteration of iterations){

Expand All @@ -34,45 +31,17 @@ describe('DELETE - Collection ', function () {
const distinct = expectations[iteration.name]

describe('deleteCollection - /collections/{collectionId}', function () {
if (iteration.name === 'stigmanadmin' ){

it('Delete test Collection, test projections - elevated stigmanadmin only',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.testCollection.collectionId}?elevate=true&projection=assets&projection=grants&projection=owners&projection=statistics&projection=stigs`)
.set('Authorization', `Bearer ${iteration.token}`)

expect(res).to.have.status(200)
expect(res.body.collectionId).to.equal(reference.testCollection.collectionId)

expect(res.body.assets).to.have.lengthOf(reference.testCollection.assetIds.length)
for(const asset of res.body.assets){
expect(reference.testCollection.assetIds).to.include(asset.assetId)
}
expect(res.body.grants).to.have.lengthOf(reference.testCollection.grantsProjected.length)
for(const grant of res.body.grants){
const userIds = reference.testCollection.grantsProjected.map(grant => grant.user.userId)
expect(userIds).to.include(grant.user.userId)
}

expect(res.body.owners).to.have.lengthOf(reference.testCollection.owners.length)
for(const owner of res.body.owners){
expect(reference.testCollection.owners).to.include(owner.userId)
}

expect(res.body.stigs).to.have.lengthOf(reference.testCollection.validStigs.length)
for(const stig of res.body.stigs){
expect(reference.testCollection.validStigs).to.include(stig.benchmarkId)
}
before(async function () {
const testCollectionClone = JSON.parse(JSON.stringify(requestBodies.resetTestCollection))
testCollectionClone.name = `Collection ` + Math.floor(Math.random() * 1000000)
tempCollection = await utils.createTempCollection(testCollectionClone)
console.log(`tempCollection: ${tempCollection.data.collectionId}`)
})

expect(res.body.statistics).to.have.property('assetCount', reference.testCollection.assetIds.length)
expect(res.body.statistics).to.have.property('grantCount', reference.testCollection.grantsProjected.length)
const deletedCollection = await utils.getCollection(reference.testCollection.collectionId)
expect(deletedCollection).to.be.undefined
})
}
it('Delete deleteCollection collection (stigmanadmin only)',async function () {
it('Delete tempCollection collection (stigmanadmin only)',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.deleteCollection.collectionId}`)
.delete(`/collections/${tempCollection.data.collectionId}`)
.set('Authorization', `Bearer ${iteration.token}`)

if(distinct.canDeleteCollection === false){
Expand All @@ -81,27 +50,34 @@ describe('DELETE - Collection ', function () {
}
expect(res).to.have.status(200)

expect(res.body.collectionId).to.equal(reference.deleteCollection.collectionId)
expect(res.body.collectionId).to.equal(tempCollection.data.collectionId)

//confirm that it is deleted
const deletedCollection = await utils.getCollection(reference.deleteCollection.collectionId)
const deletedCollection = await utils.getCollection(tempCollection.data.collectionId)
expect(deletedCollection).to.be.undefined
})

})

describe('deleteCollectionLabelById - /collections/{collectionId}/labels/{labelId}', function () {

let tempLabel = null
beforeEach(async function () {
const labelPost = JSON.parse(JSON.stringify(requestBodies.recreateCollectionLabel))
labelPost.name = `Label ` + Math.floor(Math.random() * 1000000)
tempLabel = await utils.createCollectionLabel(reference.testCollection.collectionId, labelPost)
})
it('Delete a scrap collection scrap Label',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.scrapCollection.collectionId}/labels/${reference.scrapCollection.scrapLabel}`)
.delete(`/collections/${reference.testCollection.collectionId}/labels/${tempLabel.labelId}`)
.set('Authorization', `Bearer ${iteration.token}`)
if(distinct.canModifyCollection === false){
expect(res).to.have.status(403)
return
}
expect(res).to.have.status(204)
const collection = await utils.getCollection(reference.scrapCollection.collectionId)
expect(collection.labels).to.not.include(reference.scrapCollection.scrapLabel)
const collection = await utils.getCollection(reference.testCollection.collectionId)
expect(collection.labels).to.not.include(tempLabel.labelId)
})
it("should throw SmError.NotFoundError when deleting a non-existent label.",async function () {
const labelId = uuidv4()
Expand All @@ -119,24 +95,30 @@ describe('DELETE - Collection ', function () {

describe('deleteCollectionMetadataKey - /collections/{collectionId}/metadata/keys/{key}', function () {

beforeEach(async function () {
const res = await utils.putCollection(reference.testCollection.collectionId, requestBodies.resetTestCollection)
})
it('Delete a scrap collection Metadata Key',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.scrapCollection.collectionId}/metadata/keys/${reference.scrapCollection.collectionMetadataKey}`)
.delete(`/collections/${reference.testCollection.collectionId}/metadata/keys/${reference.testCollection.collectionMetadataKey}`)
.set('Authorization', `Bearer ${iteration.token}`)

if(distinct.canModifyCollection === false){
expect(res).to.have.status(403)
return
}

expect(res).to.have.status(204)
const collection = await utils.getCollection(reference.scrapCollection.collectionId)
expect(collection.metadata).to.not.have.property(reference.scrapCollection.collectionMetadataKey)
const collection = await utils.getCollection(reference.testCollection.collectionId)
expect(collection.metadata).to.not.have.property(reference.testCollection.collectionMetadataKey)
})
})

describe('deleteReviewHistoryByCollection - /collections/{collectionId}/review-history', function () {

beforeEach(async function () {
await utils.loadAppData()
})

it('Delete review History records - retentionDate',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.testCollection.collectionId}/review-history?retentionDate=${reference.testCollection.reviewHistory.endDate}`)
Expand All @@ -150,7 +132,6 @@ describe('DELETE - Collection ', function () {
expect(res).to.have.status(200)
expect(res.body.HistoryEntriesDeleted).to.be.equal(reference.testCollection.reviewHistory.deletedEntriesByDate)
})

it('Delete review History records - date and assetId',async function () {
const res = await chai.request(config.baseUrl)
.delete(`/collections/${reference.testCollection.collectionId}/review-history?retentionDate=${reference.testCollection.reviewHistory.endDate}&assetId=${reference.testCollection.testAssetId}`)
Expand Down
31 changes: 16 additions & 15 deletions test/api/mocha/data/collection/collectionPatch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ describe('PATCH - Collection', function () {
before(async function () {
this.timeout(4000)
await utils.uploadTestStigs()
await utils.loadAppData()
})

for(const iteration of iterations) {
Expand All @@ -27,12 +26,17 @@ describe('PATCH - Collection', function () {

describe(`iteration:${iteration.name}`, function () {

beforeEach(async function () {
await utils.putCollection(reference.testCollection, requestBodies.resetTestCollection)
})

describe('updateCollection - /collections/{collectionId}', function () {
it('Patch scrap collection, send 5 new grants and metadata.',async function () {

it('Patch test collection, send 5 new grants and metadata.',async function () {

const patchRequest = requestBodies.updateCollection
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.scrapCollection.collectionId}?&projection=grants&projection=stigs`)
.patch(`/collections/${reference.testCollection.collectionId}?&projection=grants&projection=stigs`)
.set('Authorization', `Bearer ${iteration.token}`)
.send(patchRequest)

Expand All @@ -49,7 +53,7 @@ describe('PATCH - Collection', function () {

expect(res.body.grants).to.have.lengthOf(patchRequest.grants.length)
for(let stig of res.body.stigs) {
expect(stig.benchmarkId).to.be.oneOf(reference.scrapCollection.validStigs)
expect(stig.benchmarkId).to.be.oneOf(reference.testCollection.validStigs)
if(stig.benchmarkId === reference.benchmark){
expect(stig.ruleCount).to.equal(reference.checklistLength)
}
Expand All @@ -72,14 +76,12 @@ describe('PATCH - Collection', function () {
expect(res.body.error).to.equal("Unprocessable Entity.")
expect(res.body.detail).to.equal("Duplicate user in grant array")
})

})

describe('patchCollectionLabelById - /collections/{collectionId}/labels/{labelId}', function () {
it('Patch scrap collection label, change color, description and name ',async function () {
it('Patch test collection label, change color, description and name ',async function () {
const body = requestBodies.patchCollectionLabelById
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.scrapCollection.collectionId}/labels/${reference.scrapCollection.scrapLabel}`)
.patch(`/collections/${reference.testCollection.collectionId}/labels/${reference.testCollection.fullLabel}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send(body)

Expand All @@ -89,7 +91,7 @@ describe('PATCH - Collection', function () {
}
expect(res).to.have.status(200)

expect(res.body.labelId).to.equal(reference.scrapCollection.scrapLabel)
expect(res.body.labelId).to.equal(reference.testCollection.fullLabel)
expect(res.body.description).to.equal(body.description)
expect(res.body.color).to.equal(body.color)
expect(res.body.name).to.equal(body.name)
Expand All @@ -98,7 +100,7 @@ describe('PATCH - Collection', function () {

const body = requestBodies.patchCollectionLabelById
const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.scrapCollection.collectionId}/labels/${uuidv4()}`)
.patch(`/collections/${reference.testCollection.collectionId}/labels/${uuidv4()}`)
.set('Authorization', `Bearer ${iteration.token}`)
.send(body)
if(distinct.canModifyCollection === false){
Expand All @@ -109,23 +111,22 @@ describe('PATCH - Collection', function () {
expect(res.body.error).to.equal("Resource not found.")
})
})

describe('patchCollectionMetadata - /collections/{collectionId}/metadata', function () {

it('Patch scrap collection metadata',async function () {
it('Patch test collection metadata',async function () {

const res = await chai.request(config.baseUrl)
.patch(`/collections/${reference.scrapCollection.collectionId}/metadata`)
.patch(`/collections/${reference.testCollection.collectionId}/metadata`)
.set('Authorization', `Bearer ${iteration.token}`)
.send({[reference.scrapCollection.collectionMetadataKey]: reference.scrapCollection.collectionMetadataValue})
.send({[reference.testCollection.collectionMetadataKey]: reference.testCollection.collectionMetadataValue})

if(distinct.canModifyCollection === false){
expect(res).to.have.status(403)
return
}

expect(res).to.have.status(200)
expect(res.body).to.contain({[reference.scrapCollection.collectionMetadataKey]: reference.scrapCollection.collectionMetadataValue})
expect(res.body).to.contain({[reference.testCollection.collectionMetadataKey]: reference.testCollection.collectionMetadataValue})
})
})
})
Expand Down
3 changes: 1 addition & 2 deletions test/api/mocha/data/collection/collectionPut.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ describe('PUT - Collection', function () {
before(async function () {
this.timeout(4000)
await utils.uploadTestStigs()
await utils.loadAppData()
await utils.createDisabledCollectionsandAssets()
// await utils.createDisabledCollectionsandAssets()
})

for(const iteration of iterations){
Expand Down
79 changes: 78 additions & 1 deletion test/api/mocha/data/collection/requestBodies.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,83 @@ const requestBodies = {
writeStigPropsByCollectionStig: {
defaultRevisionStr: 'V1R1',
assetIds: ['62', '42', '154']
}
},
resetTestCollection:{
name: 'Collection X',
description: null,
settings: {
fields: {
detail: {
enabled: 'always',
required: 'always'
},
comment: {
enabled: 'always',
required: 'findings'
}
},
status: {
canAccept: true,
minAcceptGrant: 3,
resetCriteria: 'result'
},
history: {
maxReviews: 5
}
},
metadata: {
pocName: 'true',
pocEmail: '[email protected]',
pocPhone: '12342',
reqRar: 'true'
},
grants: [
{
userId: '1',
accessLevel: 4
},
{
userId: '45',
accessLevel: 4
},
{
userId: '87',
accessLevel: 4
},
{
userId: '44',
accessLevel: 3
},
{
userId: "21",
accessLevel: 2
},
{
userId: "85",
accessLevel: 1
},
{
userId: "86",
accessLevel: 1
}
],
labels: [
{
name: 'test-label-full',
description: '',
color: 'FF99CC'
},
{
name: 'test-label-lvl1',
description: '',
color: '99CCFF'
}
]
},
recreateCollectionLabel:{
name: 'testLabel',
description: 'test label',
color: 'FF99CC'
},
}
module.exports = requestBodies
1 change: 1 addition & 0 deletions test/api/mocha/data/review/reviewGet.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ describe('GET - Review', () => {
expect(review.assetId).to.be.oneOf(reference.testCollection.assetIds)
}
})
// this test has some odd behavior .
it('Return a list of reviews accessible to the requester, rules=not-default', async () => {
const res = await chai.request(config.baseUrl)
.get(`/collections/${reference.testCollection.collectionId}/reviews?rules=not-default`)
Expand Down
Loading

0 comments on commit 5c90ec2

Please sign in to comment.