Skip to content

Commit

Permalink
add tests fo permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
KoWeiJAC committed Dec 20, 2024
1 parent aad6787 commit def0b77
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/functions/exportSccSummaryReport.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from 'assert';
import { firebaseFunctionsTest, generateMockContext } from './helpers.js';
import { PERMISSIONS } from '../../functions/shared/permissions.js';
import exportSccSummaryReport from '../../functions/callableFunctions/exportSccSummaryReport.js';

const { wrap } = firebaseFunctionsTest;

describe('exportSccSummaryReport', () => {
context('Permission', () => {
it ('has no permission', async () => {
const wrapped = wrap(exportSccSummaryReport);
try {
await wrapped({}, generateMockContext());
} catch (e) {
assert.equal(e.code, 'permission-denied');
}
});
it ('has permission', async () => {
const wrapped = wrap(exportSccSummaryReport);
const context = generateMockContext({
permissions: [
PERMISSIONS.exercises.permissions.canReadExercises.value,
PERMISSIONS.applicationRecords.permissions.canReadApplicationRecords.value,
PERMISSIONS.applications.permissions.canReadApplications.value,
],
});
try {
await wrapped({}, context);
} catch (e) {
assert.equal(e.code, 'invalid-argument');
}
});
});
});
34 changes: 34 additions & 0 deletions test/functions/generateSccSummaryReport.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from 'assert';
import { firebaseFunctionsTest, generateMockContext } from './helpers.js';
import { PERMISSIONS } from '../../functions/shared/permissions.js';
import generateSccSummaryReport from '../../functions/callableFunctions/generateSccSummaryReport.js';

const { wrap } = firebaseFunctionsTest;

describe('generateSccSummaryReport', () => {
context('Permission', () => {
it ('has no permission', async () => {
const wrapped = wrap(generateSccSummaryReport);
try {
await wrapped({}, generateMockContext());
} catch (e) {
assert.equal(e.code, 'permission-denied');
}
});
it ('has permission', async () => {
const wrapped = wrap(generateSccSummaryReport);
const context = generateMockContext({
permissions: [
PERMISSIONS.exercises.permissions.canReadExercises.value,
PERMISSIONS.applications.permissions.canReadApplications.value,
PERMISSIONS.applicationRecords.permissions.canReadApplicationRecords.value,
],
});
try {
await wrapped({}, context);
} catch (e) {
assert.equal(e.code, 'invalid-argument');
}
});
});
});

0 comments on commit def0b77

Please sign in to comment.