diff --git a/frontend/tests/unit/components/DataExport.spec.ts b/frontend/tests/unit/components/DataExport.spec.ts index 41f965a277e61cc3cbf2927437602b8458302d7c..f41c8bf8a6769f5be275503cef28c96a2c72e772 100644 --- a/frontend/tests/unit/components/DataExport.spec.ts +++ b/frontend/tests/unit/components/DataExport.spec.ts @@ -4,6 +4,7 @@ import DataExport from '@/components/export/DataExport.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() @@ -23,17 +24,6 @@ describe('DataExport Component Unit Tests', () => { error: console.error } - // for creating test data - let students = [{ - Matrikel: 1000000, - Name: 'test', - Username: 'test', - Sum: 100, - Exam: 'test', - Password: 'test', - Scores: { type: 'test', score: 100 } - }] - before(function () { console.warn = function () {} console.error = function () {} @@ -63,7 +53,7 @@ describe('DataExport Component Unit Tests', () => { // @ts-ignore sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy()) // @ts-ignore - wrapper.vm.optionalConvertAndCreatePopup(students) + wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports) spy.called.should.equal(true) }) it('should download JSON when selected', () => { @@ -75,12 +65,12 @@ describe('DataExport Component Unit Tests', () => { // @ts-ignore sinon.replace(wrapper.vm, 'createDownloadPopup', sinon.spy()) // @ts-ignore - wrapper.vm.optionalConvertAndCreatePopup(students) + wrapper.vm.optionalConvertAndCreatePopup(testUtils.studentExports) spy.called.should.equal(false) }) it('should download obfuscated data when no mapping was selected', async () => { let wrapper = mount(DataExport, { localVue: localVue, store }) - let stub = sinon.stub().returns(Promise.resolve({ data: students })) + let stub = sinon.stub().returns(Promise.resolve({ data: testUtils.studentExports })) let spy = sinon.spy() // @ts-ignore replace ax.post because of fetch in getExportFile sinon.replace(api.default, 'post', stub) @@ -88,10 +78,20 @@ describe('DataExport Component Unit Tests', () => { sinon.replace(wrapper.vm, 'optionalConvertAndCreatePopup', spy) // @ts-ignore await wrapper.vm.getExportFile('data') - spy.called.should.equal(true) - spy.calledWithExactly(students).should.equal(true) + spy.calledWithExactly(testUtils.studentExports).should.equal(true) }) - it('should download deobfuscated data when no mapping was selected', async () => { - + it('should download deobfuscated data when mapping was selected', async () => { + let wrapper = mount(DataExport, { localVue: localVue, store }) + let stub = sinon.stub().returns(Promise.resolve({ data: testUtils.studentExports })) + let spy = sinon.spy() + // @ts-ignore + wrapper.vm.mapFile = testUtils.fakeFile + // @ts-ignore replace ax.post because of fetch in getExportFile + sinon.replace(api.default, 'post', stub) + // @ts-ignore + sinon.replace(wrapper.vm, 'getMappedExportFile', spy) + // @ts-ignore + await wrapper.vm.getExportFile('data') + spy.calledWithExactly(testUtils.studentExports).should.equal(true) }) })