Skip to content

Commit

Permalink
Merge pull request #103 from ciatph/fix/ciatph-101-async
Browse files Browse the repository at this point in the history
Fix/ciatph 101 - tests
  • Loading branch information
ciatph authored Aug 28, 2024
2 parents f3534e5 + 6e988a7 commit 7dc7e1c
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 141 deletions.
76 changes: 76 additions & 0 deletions app/__tests__/classInitialization/customSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require('dotenv').config()
const path = require('path')

const ExcelFile = require('../../src/classes/excel')
const ExcelFactory = require('../../src/classes/excelfactory')
const ColorLog = require('../../src/classes/colorlog')
const logger = new ColorLog({ isBold: true })

const checkClass = require('./checkClass')
const config = require('./config.json')

// Classes loading the default local 10-day Excel file using a custom regions config
const LOCAL_SOURCE = {
excelFactory: new ExcelFactory({ settings: config }),

excelFile: new ExcelFile({
pathToFile: path.join(__dirname, '..', '..', 'data', 'day1.xlsx'),
settings: config
})
}

// Classes loading the remote 10-day Excel file using a custom regions config
const REMOTE_SOURCE = {
excelFile: new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload4.xlsx'),
url: process.env.EXCEL_FILE_URL,
settings: config
}),

excelFactory: new ExcelFactory({
url: process.env.EXCEL_FILE_URL,
settings: config
})
}

/* eslint-disable no-undef */
describe('Class intialization using CUSTOM config', () => {
beforeAll(async () => {
return await Promise.all([
REMOTE_SOURCE.excelFile.init(),
REMOTE_SOURCE.excelFactory.init()
])
})

it('should load LOCAL_SOURCE Excel file', () => {
jest.setTimeout(40000)
logger.log('[INIT]: Started loading using "CUSTOM" config on LOCAL file')

checkClass({
excelInstance: LOCAL_SOURCE.excelFactory,
classType: ExcelFactory
})

checkClass({
excelInstance: LOCAL_SOURCE.excelFile,
classType: ExcelFile
})
})

it('should load REMOTE_SOURCE Excel file', async () => {
jest.setTimeout(20000)
logger.log('[INIT]: Started loading using "CUSTOM" config on REMOTE file')

checkClass({
excelInstance: REMOTE_SOURCE.excelFactory,
isRemote: true,
classType: ExcelFactory
})

checkClass({
excelInstance: REMOTE_SOURCE.excelFile,
isRemote: true,
classType: ExcelFile
})
})
})
72 changes: 72 additions & 0 deletions app/__tests__/classInitialization/defaultSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require('dotenv').config()
const path = require('path')

const ExcelFile = require('../../src/classes/excel')
const ExcelFactory = require('../../src/classes/excelfactory')
const ColorLog = require('../../src/classes/colorlog')
const logger = new ColorLog({ isBold: true })

const checkClass = require('./checkClass')

// Classes loading the default local 10-day Excel file using the default PAGASA seasonal config
const LOCAL_SOURCE = {
excelFactory: new ExcelFactory(),

excelFile: new ExcelFile({
pathToFile: path.join(__dirname, '..', '..', 'data', 'day1.xlsx')
})
}

// Classes loading the remote 10-day Excel file using the default PAGASA seasonal config
const REMOTE_SOURCE = {
excelFile: new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload4.xlsx'),
url: process.env.EXCEL_FILE_URL
}),

excelFactory: new ExcelFactory({
url: process.env.EXCEL_FILE_URL
})
}

/* eslint-disable no-undef */
describe('Class intialization using DEFAULT config', () => {
beforeAll(async () => {
return await Promise.all([
REMOTE_SOURCE.excelFile.init(),
REMOTE_SOURCE.excelFactory.init()
])
})

it('should load LOCAL_SOURCE Excel file', () => {
jest.setTimeout(40000)
logger.log('[INIT]: Started loading using "DEFAULT" config on LOCAL file')

checkClass({
excelInstance: LOCAL_SOURCE.excelFactory,
classType: ExcelFactory
})

checkClass({
excelInstance: LOCAL_SOURCE.excelFile,
classType: ExcelFile
})
})

it('should load REMOTE_SOURCE Excel file', async () => {
jest.setTimeout(20000)
logger.log('[INIT]: Started loading using "DEFAULT" config on REMOTE file')

checkClass({
excelInstance: REMOTE_SOURCE.excelFactory,
isRemote: true,
classType: ExcelFactory
})

checkClass({
excelInstance: REMOTE_SOURCE.excelFile,
isRemote: true,
classType: ExcelFile
})
})
})
120 changes: 0 additions & 120 deletions app/__tests__/classInitialization/fileLoading.js

This file was deleted.

17 changes: 10 additions & 7 deletions app/__tests__/municipalities/municipalitiesCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ const checkClass = require('../classInitialization/checkClass')
const createMunicipalityInstance = require('./createMunicipalityInstance')
const { arrayToString } = require('../../src/lib/utils')

// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload.xlsx'),
url: process.env.EXCEL_FILE_URL
})

/* eslint-disable no-undef */
describe('Municipalities total count match', () => {
// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload.xlsx'),
url: process.env.EXCEL_FILE_URL
beforeAll(async () => {
// Start file download
return await excelFile.init()
})

it('municipalities from provinces config should match with original Excel municipalities count', async () => {
jest.setTimeout(20000)

// Start file download
await excelFile.init()

// Create local/remote ExcelFile classes using the default PAGASA region settings
const {
excel,
config,
Expand Down
16 changes: 9 additions & 7 deletions app/__tests__/municipalities/municipalitiesPerProvinceCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ const logger = new ColorLog()
const checkClass = require('../classInitialization/checkClass')
const { arrayToString } = require('../../src/lib/utils')

// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload2.xlsx'),
url: process.env.EXCEL_FILE_URL
})

/* eslint-disable no-undef */
describe('Municipalities per province count match', () => {
// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload2.xlsx'),
url: process.env.EXCEL_FILE_URL
beforeAll(async () => {
// Start file download
return await excelFile.init()
})

it('number of parsed/processed municipalities per province should match per province count from original data', async () => {
jest.setTimeout(20000)

// Start file download
await excelFile.init()

// Parsed/processed provinces from the Excel file
const allProvinces = excelFile.listAllProvinces(true)

Expand Down
16 changes: 9 additions & 7 deletions app/__tests__/provinces/testProvinceCount.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ const checkClass = require('../classInitialization/checkClass')
const createInstances = require('./createInstances')
const updateInstances = require('./updateInstances')

// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload3.xlsx'),
url: process.env.EXCEL_FILE_URL
})

/* eslint-disable no-undef */
describe('Provinces names and count match', () => {
// Test using the latest 10-day PAGASA Excel file
const excelFile = new ExcelFile({
pathToFile: path.join(__dirname, 'excelfiledownload3.xlsx'),
url: process.env.EXCEL_FILE_URL
beforeAll(async () => {
// Start file download
return await excelFile.init()
})

it('settings (seasonal) provinces should match with (10-day) Excel provinces', async () => {
jest.setTimeout(20000)

// Start file download
await excelFile.init()

const {
allExcelProvinces,
allProvinces,
Expand Down
3 changes: 3 additions & 0 deletions app/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ module.exports = {
'/node_modules/',
'__tests__/classInitialization/checkClass.js',
'__tests__/municipalities/createMunicipalityInstance.js',
// '__tests__/municipalities/municipalitiesCount.js',
// '__tests__/municipalities/municipalitiesPerProvinceCount.js',
'__tests__/municipalities/index.js',
'__tests__/provinces/createInstances.js',
'__tests__/provinces/updateInstances.js',
// '__tests__/provinces/testProvinceCount.js',
'__tests__/provinces/index.js'
]
}

0 comments on commit 7dc7e1c

Please sign in to comment.