Skip to content
Snippets Groups Projects
Commit 3bc6af98 authored by Dominik Seeger's avatar Dominik Seeger
Browse files

added tests for studentList deobfuscation logic

parent 6539f080
No related branches found
No related tags found
1 merge request!128Merge improve testing
Pipeline #86788 passed
...@@ -94,4 +94,18 @@ describe('DataExport Component Unit Tests', () => { ...@@ -94,4 +94,18 @@ describe('DataExport Component Unit Tests', () => {
await wrapper.vm.getExportFile('data') await wrapper.vm.getExportFile('data')
spy.calledWithExactly(testUtils.studentExports).should.equal(true) spy.calledWithExactly(testUtils.studentExports).should.equal(true)
}) })
it('should correctly apply the student-map file', () => {
let wrapper = mount(DataExport, { localVue: localVue, store })
let mapStub = sinon.stub().returns(testUtils.studentMap)
let spy = sinon.spy()
// @ts-ignore
sinon.replaceGetter(wrapper.vm, 'studentMap', mapStub)
// @ts-ignore
sinon.replaceGetter(wrapper.vm, 'mapFileLoaded', sinon.stub().returns(true))
// @ts-ignore
sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy)
// @ts-ignore
wrapper.vm.getMappedExportFile(testUtils.studentExportsObfuscated)
spy.firstCall.args[0][0].Matrikel.should.equal(testUtils.studentMap['username'].matrikelNo)
})
}) })
import Vuex from 'vuex'
import { mount, createLocalVue, createWrapper } from '@vue/test-utils'
import InstanceExport from '@/components/export/InstanceExport.vue'
import sinon from 'sinon'
import chai from 'chai'
import VueRouter from 'vue-router'
import testUtils from '@/../tests/utils/testUtils'
import * as api from '@/api'
chai.should()
let localVue = createLocalVue()
localVue.use(Vuex)
localVue.use(VueRouter)
let router = new VueRouter()
// @ts-ignore
global.requestAnimationFrame = cb => cb()
describe('InstanceExport Component Unit Tests', () => {
let store: any = null
let consoleTemp = {
warn: console.warn,
error: console.error
}
before(function () {
console.warn = function () {}
console.error = function () {}
})
after(function () {
console.warn = consoleTemp.warn
console.error = consoleTemp.error
})
beforeEach(() => {
store = new Vuex.Store({
state: {}
})
})
afterEach(() => {
sinon.restore()
})
it('should correctly apply the student-map file', () => {
let wrp = mount(InstanceExport, { localVue: localVue, store })
let mapStub = sinon.stub().returns(testUtils.studentMap)
let spy = sinon.spy()
// @ts-ignore
sinon.replaceGetter(wrp.vm, 'studentMap', mapStub)
// @ts-ignore
sinon.replaceGetter(wrp.vm, 'mapFileLoaded', sinon.stub().returns(true))
// @ts-ignore
sinon.replace(wrp.vm, 'optionalConvertAndCreatePopup', spy)
// @ts-ignore
wrp.vm.getMappedExportFile(testUtils.instanceExportsObfuscated)
spy.firstCall.args[0].students[0].matrikelNo.should.equal(testUtils.studentMap['username'].matrikelNo)
})
})
\ No newline at end of file
...@@ -19,12 +19,27 @@ export default { ...@@ -19,12 +19,27 @@ export default {
Password: 'pwd', Password: 'pwd',
Scores: [{ type: 'test01', score: 100 }] Scores: [{ type: 'test01', score: 100 }]
}], }],
studentExportsObfuscated: <StudentExportItem[]> [{
Matrikel: 'username',
Name: 'name',
Username: 'username',
Sum: 100,
Exam: 'exam',
Password: 'pwd',
Scores: [{ type: 'test01', score: 100 }]
}],
instanceExports: <InstanceExportData> { instanceExports: <InstanceExportData> {
students: [{ students: [{
name: 'test', name: 'name',
matrikelNo: '1000000' matrikelNo: '1000000'
}] }]
}, },
instanceExportsObfuscated: <InstanceExportData> {
students: [{
name: 'name',
matrikelNo: 'username'
}]
},
fakeFile: <File> { fakeFile: <File> {
lastModified: 1, lastModified: 1,
name: 'Grady testUtils fake file', name: 'Grady testUtils fake file',
...@@ -33,8 +48,8 @@ export default { ...@@ -33,8 +48,8 @@ export default {
type: 'fake file' type: 'fake file'
}, },
studentMap: { studentMap: {
'1000000': { 'username': {
matrikelNo: '1000000', name: 'test' matrikelNo: '1000000', name: 'name'
} }
} },
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment