From 4ea8f3138c5628882c0c63f93683a49f6de4a2e4 Mon Sep 17 00:00:00 2001 From: Veikkosuhonen Date: Mon, 22 Jan 2024 15:17:43 +0200 Subject: [PATCH] Add doctoral spec & refactor tests dir --- tests/basic.spec.js | 4 +-- tests/dekaani.spec.js | 2 +- tests/doctoral.spec.js | 54 +++++++++++++++++++++++++++++++++++++++ tests/jory.spec.js | 2 +- tests/kosu.spec.js | 2 +- tests/lomake.spec.js | 2 +- tests/{ => util}/data.js | 0 tests/{ => util}/seed.js | 0 tests/{ => util}/utils.js | 0 9 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/doctoral.spec.js rename tests/{ => util}/data.js (100%) rename tests/{ => util}/seed.js (100%) rename tests/{ => util}/utils.js (100%) diff --git a/tests/basic.spec.js b/tests/basic.spec.js index 451937c..bec3773 100644 --- a/tests/basic.spec.js +++ b/tests/basic.spec.js @@ -1,6 +1,6 @@ import { expect, test, beforeAll } from 'vitest' -import { api } from './utils' -import { seed } from './seed' +import { api } from './util/utils' +import { seed } from './util/seed' import { mapToDegreeCode } from '../src/auth/common' beforeAll(async () => { diff --git a/tests/dekaani.spec.js b/tests/dekaani.spec.js index de08e2a..e46757e 100644 --- a/tests/dekaani.spec.js +++ b/tests/dekaani.spec.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { api } from "./utils"; +import { api } from "./util/utils"; describe.concurrent('Dekaani', () => { it('gets READ access to faculty and each programme of faculty', async () => { diff --git a/tests/doctoral.spec.js b/tests/doctoral.spec.js new file mode 100644 index 0000000..6d8ab68 --- /dev/null +++ b/tests/doctoral.spec.js @@ -0,0 +1,54 @@ +import { describe, expect, it } from "vitest"; +import { api } from "./util/utils"; + +describe.concurrent('Doctoral schools', () => { + it('Doctoral iam gives access to all doctoral schools & gives "doctoral" special group', async () => { + [ + 'hy-tohtorikoulutus-johtoryhma', 'hy-tine' + ].forEach(async (iam) => { + const res = await api.post('', { + userId: 'doctoralschools-user', + iamGroups: [iam], + }) + + expect(res.status).toBe(200) + const json = await res.json() + + const numberOfDoctoralSchools = 33 // Go to data.ts and CTR+F "level: 'doctoral'" + expect(Object.keys(json).length).toBe(numberOfDoctoralSchools + 1) // +1 because 'specialGroup' field. + expect(json).toHaveProperty('specialGroup') + expect(json.specialGroup).toHaveProperty('doctoral') + expect(json.specialGroup.doctoral).toBe(true) + }) + }) + + it('Specific doctoral school iam gives access to the corresponding doctoral programmes', async () => { + const res = await api.post('', { + userId: 'doctoralschools-user', + iamGroups: ['hy-tutkijakoulut-hymy-jory'], + }) + + expect(res.status).toBe(200) + const json = await res.json() + + ;[ + 'T920101', + 'T920102', + 'T920103', + 'T920104', + 'T920105', + 'T920106', + 'T920107', + 'T920108', + 'T920109', + 'T920110', + 'T920111', + ].forEach((programme) => { + expect(json).toHaveProperty(programme) + expect(json[programme].read).toBe(true) + expect(json[programme].write).toBeFalsy() + expect(json[programme].admin).toBeFalsy() + }) + }) + +}); diff --git a/tests/jory.spec.js b/tests/jory.spec.js index c059db1..5832dc1 100644 --- a/tests/jory.spec.js +++ b/tests/jory.spec.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { api } from "./utils"; +import { api } from "./util/utils"; import { mapToDegreeCode } from "../src/auth/common"; const degreeCode = mapToDegreeCode('200-K001') diff --git a/tests/kosu.spec.js b/tests/kosu.spec.js index 2055b84..33d2600 100644 --- a/tests/kosu.spec.js +++ b/tests/kosu.spec.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { api } from "./utils"; +import { api } from "./util/utils"; describe.concurrent('Kosu', () => { it('gets READ access to each faculty and programme of location', async () => { diff --git a/tests/lomake.spec.js b/tests/lomake.spec.js index 24c1177..ffd8496 100644 --- a/tests/lomake.spec.js +++ b/tests/lomake.spec.js @@ -1,5 +1,5 @@ import { describe, expect, it } from "vitest"; -import { api } from "./utils"; +import { api } from "./util/utils"; describe.concurrent('Lomake', () => { it('Katselmus iam gives the katselmus special group', async () => { diff --git a/tests/data.js b/tests/util/data.js similarity index 100% rename from tests/data.js rename to tests/util/data.js diff --git a/tests/seed.js b/tests/util/seed.js similarity index 100% rename from tests/seed.js rename to tests/util/seed.js diff --git a/tests/utils.js b/tests/util/utils.js similarity index 100% rename from tests/utils.js rename to tests/util/utils.js