Skip to content

Commit

Permalink
use an existing user
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Nov 28, 2023
1 parent 2f764fe commit e042eac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
21 changes: 5 additions & 16 deletions test/reportData.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import assert from 'node:assert';
import { manageUser } from '../data/temporaryUsers.js';
import { getReportData } from '../database/getReportData.js';
const reports = [
{
Expand Down Expand Up @@ -104,35 +105,23 @@ const reports = [
reportName: 'afterHoursReasons-active'
}
];
const testUser = {
userName: '~~testUser',
canLogin: true,
isAdmin: false,
permissions: {
'reports.hasRawExports': 'true',
'attendance.absences.canView': 'true',
'attendance.afterHours.canView': 'true',
'attendance.callOuts.canView': 'true',
'attendance.returnsToWork.canView': 'true'
}
};
describe('database/getReportData.js', () => {
for (const report of reports) {
it(`Exports "${report.reportName}"`, async () => {
const data = await getReportData(report.reportName, report.reportParameters ?? {}, testUser);
const data = await getReportData(report.reportName, report.reportParameters ?? {}, manageUser);
assert.ok(data);
});
}
it('Fails gracefully when missing parameter object', async () => {
const data = (await getReportData('absenceRecords-recent-byEmployeeNumber', undefined, testUser));
const data = (await getReportData('absenceRecords-recent-byEmployeeNumber', undefined, manageUser));
assert.strictEqual(data.length, 0);
});
it('Fails gracefully when missing parameter', async () => {
const data = (await getReportData('absenceRecords-recent-byEmployeeNumber', {}, testUser));
const data = (await getReportData('absenceRecords-recent-byEmployeeNumber', {}, manageUser));
assert.strictEqual(data.length, 0);
});
it('Returns undefined on unknown reports', async () => {
const data = await getReportData('qwertyuiop', {}, testUser);
const data = await getReportData('qwertyuiop', {}, manageUser);
assert.strictEqual(data, undefined);
});
});
22 changes: 5 additions & 17 deletions test/reportData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'node:assert'

import { manageUser } from '../data/temporaryUsers.js'
import { getReportData } from '../database/getReportData.js'

interface ReportData {
Expand Down Expand Up @@ -112,26 +113,13 @@ const reports: ReportData[] = [
}
]

const testUser: MonTYUser = {
userName: '~~testUser',
canLogin: true,
isAdmin: false,
permissions: {
'reports.hasRawExports': 'true',
'attendance.absences.canView': 'true',
'attendance.afterHours.canView': 'true',
'attendance.callOuts.canView': 'true',
'attendance.returnsToWork.canView': 'true'
}
}

describe('database/getReportData.js', () => {
for (const report of reports) {
it(`Exports "${report.reportName}"`, async () => {
const data = await getReportData(
report.reportName,
report.reportParameters ?? {},
testUser
manageUser
)

assert.ok(data)
Expand All @@ -142,7 +130,7 @@ describe('database/getReportData.js', () => {
const data = (await getReportData(
'absenceRecords-recent-byEmployeeNumber',
undefined,
testUser
manageUser
)) as unknown[]
assert.strictEqual(data.length, 0)
})
Expand All @@ -151,13 +139,13 @@ describe('database/getReportData.js', () => {
const data = (await getReportData(
'absenceRecords-recent-byEmployeeNumber',
{},
testUser
manageUser
)) as unknown[]
assert.strictEqual(data.length, 0)
})

it('Returns undefined on unknown reports', async () => {
const data = await getReportData('qwertyuiop', {}, testUser)
const data = await getReportData('qwertyuiop', {}, manageUser)
assert.strictEqual(data, undefined)
})
})

0 comments on commit e042eac

Please sign in to comment.