From c2ab799f46a0526bbbf0eaa5b0c78b24d0dce1e6 Mon Sep 17 00:00:00 2001 From: Katie Rischpater <98350084+the-bay-kay@users.noreply.github.com> Date: Wed, 1 Nov 2023 08:48:07 -0700 Subject: [PATCH] Added rejection test --- www/__tests__/controlHelper.test.ts | 25 +++++++++++++++---------- www/js/services/controlHelper.ts | 2 -- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/www/__tests__/controlHelper.test.ts b/www/__tests__/controlHelper.test.ts index 941839c2f..730e6e69f 100644 --- a/www/__tests__/controlHelper.test.ts +++ b/www/__tests__/controlHelper.test.ts @@ -13,19 +13,12 @@ mockFileSystem(); mockLogger(); declare let window: FsWindow; -// Test constants: -const fileName = 'testOne' -const startTime = '1969-06-16' -const endTime = '1969-06-24' -const getDataMethodsOne = getMyDataHelpers(fileName, startTime, endTime); -const writeFile = getDataMethodsOne.writeFile; - // createWriteFile does not require these objects specifically, but it // is better to test with similar data - using real data would take // up too much code space, and we cannot use getRawEnteries() in testing const generateFakeValues = (arraySize: number) => { if (arraySize <= 0) - return Promise.reject(); + return Promise.reject('reject'); const sampleDataObj : ServerData= { data: { @@ -87,10 +80,22 @@ const confirmFileExists = (fileName: string, dataCluster: ServerResponse) = }; }; +// Test constants: +const fileName = 'testOne' +const startTime = '1969-06-16' +const endTime = '1969-06-24' +const getDataMethodsOne = getMyDataHelpers(fileName, startTime, endTime); +const writeFile = getDataMethodsOne.writeFile; + +const testPromiseOne = generateFakeValues(1); +const testPromiseTwo = generateFakeValues(2222); +const badPromise = generateFakeValues(0); + it('writes a file for an array of objects', async () => { - const testPromiseOne = generateFakeValues(1); - const testPromiseTwo = generateFakeValues(2222); expect(testPromiseOne.then(writeFile)).resolves.not.toThrow(); expect(testPromiseTwo.then(writeFile)).resolves.not.toThrow(); }); +it('rejects an empty input', async () => { + expect(badPromise.then(writeFile)).rejects.toEqual('reject'); +}); \ No newline at end of file diff --git a/www/js/services/controlHelper.ts b/www/js/services/controlHelper.ts index c88d92bf3..22390a5dd 100644 --- a/www/js/services/controlHelper.ts +++ b/www/js/services/controlHelper.ts @@ -13,7 +13,6 @@ export const getMyDataHelpers = function(fileName: string, startTimeString: stri const resultList = result.phone_data; return new Promise(function(resolve, reject) { window['resolveLocalFileSystemURL'](window['cordova'].file.tempDirectory, function(fs) { - logDebug(`file system open: ${fs.name}`); fs.filesystem.root.getFile(fileName, { create: true, exclusive: false }, function (fileEntry) { logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`) fileEntry.createWriter(function (fileWriter) { @@ -39,7 +38,6 @@ export const getMyDataHelpers = function(fileName: string, startTimeString: stri const localShareData = function () { return new Promise(function(resolve, reject) { window['resolveLocalFileSystemURL'](window['cordova'].file.tempDirectory, function(fs) { - logDebug(`During share, file system open: ${fs.name}`); fs.filesystem.root.getFile(fileName, null, function(fileEntry) { logDebug(`fileEntry ${fileEntry.nativeURL} is file? ${fileEntry.isFile.toString()}`); fileEntry.file(function(file) {