Skip to content

Commit

Permalink
Added rejection test
Browse files Browse the repository at this point in the history
  • Loading branch information
the-bay-kay committed Nov 1, 2023
1 parent 24a9d95 commit c2ab799
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
25 changes: 15 additions & 10 deletions www/__tests__/controlHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>= {
data: {
Expand Down Expand Up @@ -87,10 +80,22 @@ const confirmFileExists = (fileName: string, dataCluster: ServerResponse<any>) =
};
};

// 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');
});
2 changes: 0 additions & 2 deletions www/js/services/controlHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const getMyDataHelpers = function(fileName: string, startTimeString: stri
const resultList = result.phone_data;
return new Promise<void>(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) {
Expand All @@ -39,7 +38,6 @@ export const getMyDataHelpers = function(fileName: string, startTimeString: stri
const localShareData = function () {
return new Promise<void>(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) {
Expand Down

0 comments on commit c2ab799

Please sign in to comment.