@edifice.io/communities-tests 1.0.0-develop-pedago.20250725171105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,106 @@
1
+ import { fail } from "k6";
2
+ // @ts-ignore
3
+ import { chai, describe } from "https://jslib.k6.io/k6chaijs/4.3.4.0/index.js";
4
+
5
+ import {
6
+ authenticateWeb,
7
+ getUsersOfSchool,
8
+ createAndSetRole,
9
+ linkRoleToUsers,
10
+ initStructure,
11
+ getRandomUserWithProfile,
12
+ authenticateOAuth2,
13
+ getRolesOfStructure,
14
+ Structure,
15
+ createOAuthClient,
16
+ logout,
17
+ } from "../../node_modules/edifice-k6-commons/dist/index.js";
18
+
19
+ import { runCrudTests } from "./utils/_community-tests.utils.ts";
20
+ import {
21
+ CreateCommunityParams,
22
+ UpdateCommunityParams,
23
+ } from "./utils/_community-api.utils.ts";
24
+
25
+ chai.config.logFailures = true;
26
+
27
+ export const options = {
28
+ setupTimeout: "1h",
29
+ maxRedirects: 0,
30
+ thresholds: {
31
+ checks: ["rate == 1.00"],
32
+ },
33
+ scenarios: {
34
+ communityOAuthTest: {
35
+ exec: "testCommunityOAuthApi",
36
+ executor: "per-vu-iterations",
37
+ vus: 1,
38
+ maxDuration: "1m",
39
+ gracefulStop: "5s",
40
+ },
41
+ },
42
+ };
43
+
44
+ const timestamp = new Date().toISOString();
45
+ const schoolName = `IT Community`;
46
+ const clientID = `app-${schoolName}`;
47
+
48
+ export function setup(): Structure {
49
+ let structure: Structure = {} as Structure;
50
+ describe("[CommunityOAuth] Initialize data", () => {
51
+ authenticateWeb(__ENV.ADMC_LOGIN, __ENV.ADMC_PASSWORD);
52
+ structure = initStructure(schoolName, "tiny");
53
+ const role = createAndSetRole("Communities");
54
+ const groups = getRolesOfStructure(structure.id);
55
+ linkRoleToUsers(
56
+ structure,
57
+ role,
58
+ groups.map((g: any) => g.name),
59
+ );
60
+ createOAuthClient(
61
+ {
62
+ name: clientID,
63
+ },
64
+ structure.id,
65
+ );
66
+ });
67
+ return structure;
68
+ }
69
+
70
+ export function testCommunityOAuthApi(structure: Structure) {
71
+ // Community data
72
+ const communityData: CreateCommunityParams = {
73
+ title: `IntegrationTest - Community OAuth ${timestamp}`,
74
+ type: "FREE",
75
+ schoolYearStart: 2025,
76
+ schoolYearEnd: 2026,
77
+ discussionEnabled: true,
78
+ welcomeNote: "Welcome to this test community via OAuth",
79
+ invitations: {
80
+ users: [],
81
+ },
82
+ };
83
+
84
+ // Updated community data for testing PATCH
85
+ const updateData: UpdateCommunityParams = {
86
+ title: `IntegrationTest - Updated Community OAuth ${timestamp}`,
87
+ discussionEnabled: false,
88
+ type: "FREE",
89
+ };
90
+
91
+ describe("[Community API Test with OAuth Authentication]", () => {
92
+ authenticateWeb(__ENV.ADMC_LOGIN, __ENV.ADMC_PASSWORD);
93
+ const users = getUsersOfSchool(structure);
94
+ const teacher = getRandomUserWithProfile(users, "Teacher");
95
+ logout();
96
+ const authenticated = authenticateOAuth2(
97
+ teacher.login,
98
+ "password",
99
+ clientID,
100
+ );
101
+ if (!authenticated) {
102
+ fail("Authentication failed");
103
+ }
104
+ runCrudTests(communityData, updateData);
105
+ });
106
+ }