From 6346965e5227b483f022546bc5e7c7bdeb9eb591 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Sat, 9 Mar 2024 14:30:46 -0300 Subject: [PATCH 1/3] Migrating validate-json.js --- __tests__/__main__/validate-json.js | 37 ++++++++++++------------ __tests__/electron-mocha-main.config.cjs | 2 +- jest.config.js | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/__tests__/__main__/validate-json.js b/__tests__/__main__/validate-json.js index 30858d05..bc9c1505 100644 --- a/__tests__/__main__/validate-json.js +++ b/__tests__/__main__/validate-json.js @@ -1,7 +1,8 @@ /* eslint-disable no-undef */ 'use strict'; -const assert = require('assert'); +import assert from 'assert'; + import { validateJSON } from '../../js/validate-json.js'; describe('Validate json', function() @@ -16,12 +17,12 @@ describe('Validate json', function() const invalidTypeValue = [{ 'type': 'not valid type', 'date': '2020-06-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidTypeType = [{ 'type': ['not valid type'], 'date': '2020-06-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validWaivedType), true); assert.strictEqual(validateJSON(validFlexibleType), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidTypeValue), false); assert.strictEqual(validateJSON(invalidTypeType), false); @@ -34,7 +35,7 @@ describe('Validate json', function() const validFlexibleDate2 = [{ 'type': 'flexible', 'date': '2020-6-3', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const validWaivedDate1 = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '08:00' }]; const validWaivedDate2 = [{ 'type': 'waived', 'date': '2020-6-3', 'data': 'waived', 'hours': '08:00' }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validFlexibleDate1), true); assert.strictEqual(validateJSON(validFlexibleDate2), true); @@ -51,12 +52,12 @@ describe('Validate json', function() const invalidDateType = [{ 'type': 'flexible', 'date': ['2020-06-13'], 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidDateValue = [{ 'type': 'flexible', 'date': '2020-26-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidDayInMonth = [{ 'type': 'flexible', 'date': '2020-04-31', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validWaivedDate), true); assert.strictEqual(validateJSON(validFlexibleDate), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidDateFormat), false); assert.strictEqual(validateJSON(invalidDateType), false); @@ -69,11 +70,11 @@ describe('Validate json', function() { const validData = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '08:00' }]; const invalidDataType = [{ 'type': 'waived', 'date': '2020-06-03', 'data': ['waived'], 'hours': '08:00' }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validData), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidDataType), false); }); @@ -87,12 +88,12 @@ describe('Validate json', function() const invalidHoursType = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': 8 }]; const invalidHoursValue = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '30:00' }]; const invalidHoursValueNegative = [{ 'type': 'waived', 'date': '2020-06-03', 'data': 'waived', 'hours': '-01:00' }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validHours), true); assert.strictEqual(validateJSON(validHours2), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidHoursFormat), false); assert.strictEqual(validateJSON(invalidHoursType), false); @@ -111,11 +112,11 @@ describe('Validate json', function() const invalidValuesType = [{ 'type': 'flexible', 'date': ['2020-06-03'], 'values': '08:00' }]; const invalidValuesValue = [{ 'type': 'flexible', 'date': '2020-26-03', 'values': ['80:00', '12:00', '13:00', '14:00'] }]; const invalidPointsInTime = [{ 'type': 'flexible', 'date': '2020-02-01', 'values': ['08:00', '07:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validValues), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidValuesFormat1), false); assert.strictEqual(validateJSON(invalidValuesFormat2), false); @@ -132,7 +133,7 @@ describe('Validate json', function() const invalidDay = [{ 'type': 'flexible', 'date': '2020-12-00', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidDay2 = [{ 'type': 'flexible', 'date': '2020-12-32', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { for (let i = 1; i <= 9; i++) { @@ -145,7 +146,7 @@ describe('Validate json', function() assert.strictEqual(validateJSON(restDays), true); } }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidDay), false); assert.strictEqual(validateJSON(invalidDay2), false); @@ -157,7 +158,7 @@ describe('Validate json', function() const invalidMonth = [{ 'type': 'flexible', 'date': '2020-00-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidMonth2 = [{ 'type': 'flexible', 'date': '2020-13-03', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { for (let i = 1; i <= 9; i++) { @@ -170,7 +171,7 @@ describe('Validate json', function() assert.strictEqual(validateJSON(restMonths), true); } }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidMonth), false); assert.strictEqual(validateJSON(invalidMonth2), false); @@ -182,12 +183,12 @@ describe('Validate json', function() const validLeapYear = [{ 'type': 'flexible', 'date': '2020-02-29', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; const invalidLeapYear = [{ 'type': 'flexible', 'date': '2021-02-29', 'values': ['08:00', '12:00', '13:00', '14:00'] }]; - test('should be valid JSON', () => + it('should be valid JSON', () => { assert.strictEqual(validateJSON(validLeapYear), true); }); - test('should not be valid JSON', () => + it('should not be valid JSON', () => { assert.strictEqual(validateJSON(invalidLeapYear), false); }); diff --git a/__tests__/electron-mocha-main.config.cjs b/__tests__/electron-mocha-main.config.cjs index a50de41a..ec80a601 100644 --- a/__tests__/electron-mocha-main.config.cjs +++ b/__tests__/electron-mocha-main.config.cjs @@ -1,5 +1,5 @@ const data = require('./mocha-base.config.cjs'); -data.spec = ['__tests__/__main__/time-math.js']; +data.spec = ['__tests__/__main__/{time-math,validate-json}.js']; module.exports = data; diff --git a/jest.config.js b/jest.config.js index dca10e3a..0af43b31 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,7 @@ module.exports = { displayName: ' MAIN', runner: '@jest-runner/electron/main', testEnvironment: 'node', - testMatch: ['**/__tests__/**main**/*.js', '!**/time-math.js'] + testMatch: ['**/__tests__/**main**/*.js', '!**/{time-math,validate-json}.js'] }, { displayName: 'RENDERER', From ed01146f7e17534f628e82c5dc017e14556c6413 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Sat, 9 Mar 2024 15:06:27 -0300 Subject: [PATCH 2/3] Migrating date-aux.js --- __tests__/__main__/date-aux.js | 13 +++++++------ __tests__/electron-mocha-main.config.cjs | 2 +- jest.config.js | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/__tests__/__main__/date-aux.js b/__tests__/__main__/date-aux.js index d955ba2c..3d63345b 100644 --- a/__tests__/__main__/date-aux.js +++ b/__tests__/__main__/date-aux.js @@ -1,7 +1,8 @@ /* eslint-disable no-undef */ 'use strict'; -const assert = require('assert'); +import assert from 'assert'; + import { getDateStr, getCurrentDateTimeStr, getMonthLength } from '../../js/date-aux.js'; describe('Date Functions', () => @@ -12,12 +13,12 @@ describe('Date Functions', () => describe('getDateStr(Date())', () => { - test('Given a JS Date() object, should return YYYY-MM-DD', () => + it('Given a JS Date() object, should return YYYY-MM-DD', () => { assert.strictEqual(getDateStr(testDate), expectedDate); }); - test('Given an insane object, should return an error', () => + it('Given an insane object, should return an error', () => { assert.notStrictEqual(getDateStr(badDate), expectedDate); }); @@ -26,7 +27,7 @@ describe('Date Functions', () => describe('getMonthLength(Year, Month)', () => { const testYear = 2024; - test('Given for the Year(2024) and Months, should return number of days in month', () => + it('Given for the Year(2024) and Months, should return number of days in month', () => { assert.strictEqual(getMonthLength(testYear, 0), 31); assert.strictEqual(getMonthLength(testYear, 1), 29); @@ -48,12 +49,12 @@ describe('Date Functions', () => const looseRegexCurrentDateTime = /(\d{4}_\d{2}_\d{2}_\d{2}_\d{2}_\d{2})/g; const regexCurrentDateTime = /(\d{4}_(0[1-9]|1[0-2])_(0[1-9]|[12]\d|3[01])_(0\d|1\d|2[0-3])_([0-5]\d)_([0-5]\d))/g; - test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters making sure it accepts digits', () => + it('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters making sure it accepts digits', () => { assert.strictEqual(looseRegexCurrentDateTime.test(getCurrentDateTimeStr()), true); }); - test('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters', () => + it('Should return Current Date Time string in YYYY_MM_DD_HH_MM_SS format with no spaces or unexpected characters', () => { assert.strictEqual(regexCurrentDateTime.test(getCurrentDateTimeStr()), true); }); diff --git a/__tests__/electron-mocha-main.config.cjs b/__tests__/electron-mocha-main.config.cjs index ec80a601..73dc821f 100644 --- a/__tests__/electron-mocha-main.config.cjs +++ b/__tests__/electron-mocha-main.config.cjs @@ -1,5 +1,5 @@ const data = require('./mocha-base.config.cjs'); -data.spec = ['__tests__/__main__/{time-math,validate-json}.js']; +data.spec = ['__tests__/__main__/{date-aux,time-math,validate-json}.js']; module.exports = data; diff --git a/jest.config.js b/jest.config.js index 0af43b31..580a659e 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,7 @@ module.exports = { displayName: ' MAIN', runner: '@jest-runner/electron/main', testEnvironment: 'node', - testMatch: ['**/__tests__/**main**/*.js', '!**/{time-math,validate-json}.js'] + testMatch: ['**/__tests__/**main**/*.js', '!**/{date-aux,time-math,validate-json}.js'] }, { displayName: 'RENDERER', From 85fe6bf1c1f4e156205118bfcb1523f5abe04404 Mon Sep 17 00:00:00 2001 From: Arthur Araujo Date: Sat, 9 Mar 2024 15:11:55 -0300 Subject: [PATCH 3/3] Migrating import-export.js --- __tests__/__main__/import-export.js | 38 ++++++++++++------------ __tests__/electron-mocha-main.config.cjs | 2 +- jest.config.js | 2 +- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/__tests__/__main__/import-export.js b/__tests__/__main__/import-export.js index ba5c052f..8224d97f 100644 --- a/__tests__/__main__/import-export.js +++ b/__tests__/__main__/import-export.js @@ -1,17 +1,17 @@ /* eslint-disable no-undef */ 'use strict'; -const assert = require('assert'); -const { +import assert from 'assert'; +import Store from 'electron-store'; +import fs from 'fs'; +import path from 'path'; + +import { exportDatabaseToFile, importDatabaseFromFile, migrateFixedDbToFlexible, - validEntry -} = require('../../js/import-export'); - -import fs from 'fs'; -import Store from 'electron-store'; -import path from 'path'; + validEntry, +} from '../../js/import-export.js'; describe('Import export', function() { @@ -27,14 +27,14 @@ describe('Import export', function() const badFlexibleEntry = {'type': 'flexible', 'date': '2020-06-03', 'values': ['not-an-hour']}; const badFlexibleEntry2 = {'type': 'flexible', 'date': '2020-06-03', 'values': 'not-an-array'}; const badWaivedEntry = {'type': 'regular', 'date': '2020-06-03', 'data': 'day-begin', 'hours': 'not-an-hour'}; - test('should be valid', () => + it('should be valid', () => { assert.strictEqual(validEntry(goodRegularEntry), true); assert.strictEqual(validEntry(goodWaivedEntry), true); assert.strictEqual(validEntry(goodFlexibleEntry), true); }); - test('should not be valid', () => + it('should not be valid', () => { assert.strictEqual(validEntry(badRegularEntry), false); assert.strictEqual(validEntry(badWaivedEntry), false); @@ -81,7 +81,7 @@ describe('Import export', function() describe('exportDatabaseToFile', function() { - test('Check that export works', () => + it('Check that export works', () => { assert.strictEqual(exportDatabaseToFile(path.join(folder, 'exported_file.ttldb')), true); assert.strictEqual(exportDatabaseToFile('/not/a/valid/path'), false); @@ -100,7 +100,7 @@ describe('Import export', function() describe('importDatabaseFromFile', function() { - test('Check that import works', () => + it('Check that import works', () => { assert.strictEqual(importDatabaseFromFile([path.join(folder, 'exported_file.ttldb')])['result'], true); assert.strictEqual(importDatabaseFromFile(['/not/a/valid/path'])['result'], false); @@ -117,15 +117,15 @@ describe('Import export', function() describe('migrateFixedDbToFlexible', function() { - test('Check that migration works', () => + it('Check that migration works', () => { assert.strictEqual(flexibleStore.size, 2); flexibleStore.clear(); assert.strictEqual(flexibleStore.size, 0); migrateFixedDbToFlexible(); assert.strictEqual(flexibleStore.size, 2); - expect(flexibleStore.get('2020-3-1')).toStrictEqual(migratedFlexibleEntries['2020-3-1']); - expect(flexibleStore.get('2020-3-2')).toStrictEqual(migratedFlexibleEntries['2020-3-2']); + assert.deepStrictEqual(flexibleStore.get('2020-3-1'), migratedFlexibleEntries['2020-3-1']); + assert.deepStrictEqual(flexibleStore.get('2020-3-2'), migratedFlexibleEntries['2020-3-2']); }); }); @@ -146,18 +146,18 @@ describe('Import export', function() describe('importDatabaseFromFile (mixedContent)', function() { - test('Check that import works', () => + it('Check that import works', () => { flexibleStore.clear(); assert.strictEqual(flexibleStore.size, 0); assert.strictEqual(importDatabaseFromFile([mixedEntriesFile])['result'], true); assert.strictEqual(flexibleStore.size, 2); - expect(flexibleStore.get('2020-2-1')).toStrictEqual(expectedMixedEntries['2020-2-1']); - expect(flexibleStore.get('2020-5-3')).toStrictEqual(expectedMixedEntries['2020-5-3']); + assert.deepStrictEqual(flexibleStore.get('2020-2-1'), expectedMixedEntries['2020-2-1']); + assert.deepStrictEqual(flexibleStore.get('2020-5-3'), expectedMixedEntries['2020-5-3']); }); }); - afterAll(() => + after(() => { fs.rmSync(folder, {recursive: true}); }); diff --git a/__tests__/electron-mocha-main.config.cjs b/__tests__/electron-mocha-main.config.cjs index 73dc821f..b25537da 100644 --- a/__tests__/electron-mocha-main.config.cjs +++ b/__tests__/electron-mocha-main.config.cjs @@ -1,5 +1,5 @@ const data = require('./mocha-base.config.cjs'); -data.spec = ['__tests__/__main__/{date-aux,time-math,validate-json}.js']; +data.spec = ['__tests__/__main__/{date-aux,import-export,time-math,validate-json}.js']; module.exports = data; diff --git a/jest.config.js b/jest.config.js index 580a659e..00713781 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,7 +7,7 @@ module.exports = { displayName: ' MAIN', runner: '@jest-runner/electron/main', testEnvironment: 'node', - testMatch: ['**/__tests__/**main**/*.js', '!**/{date-aux,time-math,validate-json}.js'] + testMatch: ['**/__tests__/**main**/*.js', '!**/{date-aux,import-export,time-math,validate-json}.js'] }, { displayName: 'RENDERER',