Skip to content

Commit

Permalink
cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Oct 13, 2023
1 parent 6599be6 commit b3093ea
Show file tree
Hide file tree
Showing 15 changed files with 277 additions and 241 deletions.
22 changes: 11 additions & 11 deletions test/0_purgeTestingDatabases.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as assert from "assert";
import { unlink } from "fs";
import { parkingDB_testing, nhtsaDB_testing } from "../data/databasePaths.js";
import { initializeDatabase as initializeParkingDatabase } from "../database/parkingDB/initializeDatabase.js";
import { initNHTSADB } from "../database/initializeDatabase.js";
describe("Reinitialize " + parkingDB_testing, () => {
it("Purges " + parkingDB_testing, (done) => {
import * as assert from 'node:assert';
import { unlink } from 'node:fs';
import { parkingDB_testing, nhtsaDB_testing } from '../data/databasePaths.js';
import { initNHTSADB } from '../database/nhtsaDB/initializeDatabase.js';
import { initializeDatabase as initializeParkingDatabase } from '../database/parkingDB/initializeDatabase.js';
describe('Reinitialize ' + parkingDB_testing, () => {
it('Purges ' + parkingDB_testing, (done) => {
unlink(parkingDB_testing, (error) => {
if (error) {
assert.fail();
Expand All @@ -15,13 +15,13 @@ describe("Reinitialize " + parkingDB_testing, () => {
done();
});
});
it("Creates " + parkingDB_testing, () => {
it('Creates ' + parkingDB_testing, () => {
const success = initializeParkingDatabase();
assert.ok(success);
});
});
describe("Reinitialize " + nhtsaDB_testing, () => {
it("Purges " + nhtsaDB_testing, (done) => {
describe('Reinitialize ' + nhtsaDB_testing, () => {
it('Purges ' + nhtsaDB_testing, (done) => {
unlink(nhtsaDB_testing, (error) => {
if (error) {
assert.fail();
Expand All @@ -32,7 +32,7 @@ describe("Reinitialize " + nhtsaDB_testing, () => {
done();
});
});
it("Creates " + nhtsaDB_testing, () => {
it('Creates ' + nhtsaDB_testing, () => {
const success = initNHTSADB();
assert.ok(success);
});
Expand Down
65 changes: 31 additions & 34 deletions test/0_purgeTestingDatabases.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
/* eslint-disable unicorn/filename-case */
/* eslint-disable unicorn/filename-case, eslint-comments/disable-enable-pair */

import * as assert from "assert";
import * as assert from 'node:assert'
import { unlink } from 'node:fs'

import { unlink } from "fs";
import { parkingDB_testing, nhtsaDB_testing } from '../data/databasePaths.js'
import { initNHTSADB } from '../database/nhtsaDB/initializeDatabase.js'
import { initializeDatabase as initializeParkingDatabase } from '../database/parkingDB/initializeDatabase.js'

import { parkingDB_testing, nhtsaDB_testing } from "../data/databasePaths.js";
import { initializeDatabase as initializeParkingDatabase } from "../database/parkingDB/initializeDatabase.js";
import { initNHTSADB } from "../database/initializeDatabase.js";

describe("Reinitialize " + parkingDB_testing, () => {

it("Purges " + parkingDB_testing, (done) => {
describe('Reinitialize ' + parkingDB_testing, () => {
it('Purges ' + parkingDB_testing, (done) => {
unlink(parkingDB_testing, (error) => {
if (error) {
assert.fail()
} else {
assert.ok(true);
assert.ok(true)
}
done();
});
});

it("Creates " + parkingDB_testing, () => {
const success = initializeParkingDatabase();
assert.ok(success);
});
});

describe("Reinitialize " + nhtsaDB_testing, () => {

it("Purges " + nhtsaDB_testing, (done) => {
done()
})
})

it('Creates ' + parkingDB_testing, () => {
const success = initializeParkingDatabase()
assert.ok(success)
})
})

describe('Reinitialize ' + nhtsaDB_testing, () => {
it('Purges ' + nhtsaDB_testing, (done) => {
unlink(nhtsaDB_testing, (error) => {
if (error) {
assert.fail()
} else {
assert.ok(true);
assert.ok(true)
}
done();
});
});

it("Creates " + nhtsaDB_testing, () => {
const success = initNHTSADB();
assert.ok(success);
});
});
done()
})
})

it('Creates ' + nhtsaDB_testing, () => {
const success = initNHTSADB()
assert.ok(success)
})
})
29 changes: 15 additions & 14 deletions test/2_configFunctions.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import * as assert from "assert";
import * as configFunctions from "../helpers/functions.config.js";
describe("helpers/configFunctions", () => {
describe("#getProperty", () => {
it("should include string value for property \"parkingTickets.ticketNumber.fieldLabel\"", () => {
assert.strictEqual(typeof configFunctions.getProperty("parkingTickets.ticketNumber.fieldLabel"), "string");
import * as assert from 'node:assert';
import * as configFunctions from '../helpers/functions.config.js';
describe('helpers/configFunctions', () => {
describe('#getProperty', () => {
it('should include string value for property "parkingTickets.ticketNumber.fieldLabel"', () => {
assert.strictEqual(typeof configFunctions.getProperty('parkingTickets.ticketNumber.fieldLabel'), 'string');
});
it("should return a string from function property \"parkingTickets.ticketNumber.nextTicketNumberFn\"", () => {
assert.strictEqual(typeof configFunctions.getProperty("parkingTickets.ticketNumber.nextTicketNumberFn")(""), "string");
it('should return a string from function property "parkingTickets.ticketNumber.nextTicketNumberFn"', () => {
assert.strictEqual(typeof configFunctions.getProperty('parkingTickets.ticketNumber.nextTicketNumberFn')(''), 'string');
});
});
describe("#getParkingTicketStatus()", () => {
it("should include a ticket status \"paid\"", () => {
assert.ok(configFunctions.getParkingTicketStatus("paid"));
describe('#getParkingTicketStatus()', () => {
it('should include a ticket status "paid"', () => {
assert.ok(configFunctions.getParkingTicketStatus('paid'));
});
});
describe("#getLicencePlateLocationProperties()", () => {
it("should include the location \"CA\", \"ON\"", () => {
assert.strictEqual(configFunctions.getLicencePlateLocationProperties("CA", "ON").licencePlateProvinceAlias, "Ontario");
describe('#getLicencePlateLocationProperties()', () => {
it('should include the location "CA", "ON"', () => {
assert.strictEqual(configFunctions.getLicencePlateLocationProperties('CA', 'ON')
.licencePlateProvinceAlias, 'Ontario');
});
});
});
76 changes: 43 additions & 33 deletions test/2_configFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
/* eslint-disable unicorn/filename-case */

import * as assert from "assert";

import * as configFunctions from "../helpers/functions.config.js";


describe("helpers/configFunctions", () => {

describe("#getProperty", () => {
it("should include string value for property \"parkingTickets.ticketNumber.fieldLabel\"", () => {
assert.strictEqual(typeof configFunctions.getProperty("parkingTickets.ticketNumber.fieldLabel"), "string");
});

it("should return a string from function property \"parkingTickets.ticketNumber.nextTicketNumberFn\"", () => {
assert.strictEqual(typeof configFunctions.getProperty("parkingTickets.ticketNumber.nextTicketNumberFn")(""), "string");
});


});

describe("#getParkingTicketStatus()", () => {
it("should include a ticket status \"paid\"", () => {
assert.ok(configFunctions.getParkingTicketStatus("paid"));
});
});

describe("#getLicencePlateLocationProperties()", () => {
it("should include the location \"CA\", \"ON\"", () => {
assert.strictEqual(configFunctions.getLicencePlateLocationProperties("CA", "ON").licencePlateProvinceAlias, "Ontario");
});
});
});
/* eslint-disable unicorn/filename-case, eslint-comments/disable-enable-pair */

import * as assert from 'node:assert'

import * as configFunctions from '../helpers/functions.config.js'

describe('helpers/configFunctions', () => {
describe('#getProperty', () => {
it('should include string value for property "parkingTickets.ticketNumber.fieldLabel"', () => {
assert.strictEqual(
typeof configFunctions.getProperty(
'parkingTickets.ticketNumber.fieldLabel'
),
'string'
)
})

it('should return a string from function property "parkingTickets.ticketNumber.nextTicketNumberFn"', () => {
assert.strictEqual(
typeof configFunctions.getProperty(
'parkingTickets.ticketNumber.nextTicketNumberFn'
)(''),
'string'
)
})
})

describe('#getParkingTicketStatus()', () => {
it('should include a ticket status "paid"', () => {
assert.ok(configFunctions.getParkingTicketStatus('paid'))
})
})

describe('#getLicencePlateLocationProperties()', () => {
it('should include the location "CA", "ON"', () => {
assert.strictEqual(
configFunctions.getLicencePlateLocationProperties('CA', 'ON')
.licencePlateProvinceAlias,
'Ontario'
)
})
})
})
4 changes: 2 additions & 2 deletions test/_globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="qs" />
import type { Request } from "express";
import type { Session } from "express-session";
import type { Request } from 'express';
import type { Session } from 'express-session';
export declare const testView = "*testView";
export declare const testUpdate = "*testUpdate";
export declare const testAdmin = "*testAdmin";
Expand Down
16 changes: 8 additions & 8 deletions test/_globals.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as configFunctions from "../helpers/functions.config.js";
export const testView = "*testView";
export const testUpdate = "*testUpdate";
export const testAdmin = "*testAdmin";
import * as configFunctions from '../helpers/functions.config.js';
export const testView = '*testView';
export const testUpdate = '*testUpdate';
export const testAdmin = '*testAdmin';
export const portNumber = 4000;
export const fakeViewOnlySession = {
id: "",
id: '',
cookie: undefined,
destroy: undefined,
regenerate: undefined,
Expand All @@ -13,7 +13,7 @@ export const fakeViewOnlySession = {
save: undefined,
touch: undefined,
user: {
userName: configFunctions.getProperty("users.testing")[0],
userName: configFunctions.getProperty('users.testing')[0],
userProperties: {
canUpdate: false,
isAdmin: false,
Expand All @@ -22,7 +22,7 @@ export const fakeViewOnlySession = {
}
};
export const fakeAdminSession = {
id: "",
id: '',
cookie: undefined,
destroy: undefined,
regenerate: undefined,
Expand All @@ -31,7 +31,7 @@ export const fakeAdminSession = {
save: undefined,
touch: undefined,
user: {
userName: configFunctions.getProperty("users.testing")[0],
userName: configFunctions.getProperty('users.testing')[0],
userProperties: {
canUpdate: true,
isAdmin: true,
Expand Down
52 changes: 21 additions & 31 deletions test/_globals.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import type { Request } from "express";
import type { Session } from "express-session";
import type { Request } from 'express'
import type { Session } from 'express-session'

import * as configFunctions from "../helpers/functions.config.js";
import * as configFunctions from '../helpers/functions.config.js'

export const testView = '*testView'
export const testUpdate = '*testUpdate'
export const testAdmin = '*testAdmin'

export const testView = "*testView";
export const testUpdate = "*testUpdate";
export const testAdmin = "*testAdmin";


export const portNumber = 4000;

export const portNumber = 4000

export const fakeViewOnlySession: Session = {
id: "",
id: '',
cookie: undefined,
destroy: undefined,
regenerate: undefined,
Expand All @@ -22,18 +19,17 @@ export const fakeViewOnlySession: Session = {
save: undefined,
touch: undefined,
user: {
userName: configFunctions.getProperty("users.testing")[0],
userName: configFunctions.getProperty('users.testing')[0],
userProperties: {
canUpdate: false,
isAdmin: false,
isOperator: false
}
}
};

}

export const fakeAdminSession: Session = {
id: "",
id: '',
cookie: undefined,
destroy: undefined,
regenerate: undefined,
Expand All @@ -42,18 +38,17 @@ export const fakeAdminSession: Session = {
save: undefined,
touch: undefined,
user: {
userName: configFunctions.getProperty("users.testing")[0],
userName: configFunctions.getProperty('users.testing')[0],
userProperties: {
canUpdate: true,
isAdmin: true,
isOperator: true
}
}
};

}

export const fakeRequest: Request = {
async * [Symbol.asyncIterator]() { },
async *[Symbol.asyncIterator]() {},
_destroy: undefined,
_read: undefined,
accepted: undefined,
Expand Down Expand Up @@ -135,17 +130,12 @@ export const fakeRequest: Request = {
url: undefined,
wrap: undefined,
xhr: undefined
}

};


export const fakeViewOnlyRequest =
Object.assign({}, fakeRequest, {
session: fakeViewOnlySession
});

export const fakeViewOnlyRequest = Object.assign({}, fakeRequest, {
session: fakeViewOnlySession
})

export const fakeAdminRequest =
Object.assign({}, fakeRequest, {
session: fakeAdminSession
});
export const fakeAdminRequest = Object.assign({}, fakeRequest, {
session: fakeAdminSession
})
Loading

0 comments on commit b3093ea

Please sign in to comment.