Skip to content

Commit 36d3d36

Browse files
Make it more human-proof to version bump (#4)
Make it more human-proof to version bump Add more unit test Co-authored-by: johan <johan.friedrich@everbridge.com>
1 parent b148080 commit 36d3d36

5 files changed

Lines changed: 371 additions & 2 deletions

File tree

bump-version.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// deno run --allow-read --allow-write bump-version.ts [major|minor|patch]
2+
3+
let [bumpType] = Deno.args;
4+
if (!bumpType) {
5+
const answer = prompt('No argument provided. Default to patch? [Y/n]')?.trim().toLowerCase();
6+
if (answer === '' || answer === 'y' || answer === 'yes') {
7+
bumpType = 'patch';
8+
console.log('Defaulting to patch.');
9+
} else {
10+
console.log('Aborted.');
11+
Deno.exit(0);
12+
}
13+
}
14+
if (!['major', 'minor', 'patch'].includes(bumpType)) {
15+
console.error('Usage: deno task bump [major|minor|patch]');
16+
Deno.exit(1);
17+
}
18+
19+
const denoJsonPath = './deno.json';
20+
const denoJsonRaw = await Deno.readTextFile(denoJsonPath);
21+
const denoJson = JSON.parse(denoJsonRaw);
22+
23+
if (!denoJson.version) {
24+
console.error('No version key found in deno.json');
25+
Deno.exit(1);
26+
}
27+
28+
const versionParts = denoJson.version.split('.').map(Number);
29+
if (versionParts.length !== 3 || versionParts.some(isNaN)) {
30+
console.error('Invalid version format in deno.json. Expected format: x.y.z');
31+
Deno.exit(1);
32+
}
33+
34+
const oldVersion = denoJson.version;
35+
let [major, minor, patch] = versionParts;
36+
37+
switch (bumpType) {
38+
case 'major':
39+
major++;
40+
minor = 0;
41+
patch = 0;
42+
break;
43+
case 'minor':
44+
minor++;
45+
patch = 0;
46+
break;
47+
case 'patch':
48+
patch++;
49+
break;
50+
}
51+
52+
const newVersion = `${major}.${minor}.${patch}`;
53+
denoJson.version = newVersion;
54+
55+
await Deno.writeTextFile(denoJsonPath, JSON.stringify(denoJson, null, 2) + '\n');
56+
console.log(`Bumped version from ${oldVersion} to ${newVersion}`);

deno.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@johanfive/xmas",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"exports": "./src/index.ts",
55
"license": "MIT",
66
"imports": {
@@ -11,7 +11,8 @@
1111
"tasks": {
1212
"cache": "DENO_TLS_CA_STORE=system deno cache --reload src/**/*.ts",
1313
"sandbox": "DENO_TLS_CA_STORE=system deno run --allow-read --allow-net --env-file=sandbox/.env --allow-env sandbox/index.ts",
14-
"sandbox:validate-docs": "DENO_TLS_CA_STORE=system deno run --allow-read --allow-net --env-file=sandbox/.env --allow-env sandbox/validate-docs.ts"
14+
"sandbox:validate-docs": "DENO_TLS_CA_STORE=system deno run --allow-read --allow-net --env-file=sandbox/.env --allow-env sandbox/validate-docs.ts",
15+
"bump": "deno run --allow-read --allow-write bump-version.ts"
1516
},
1617
"fmt": {
1718
"singleQuote": true,

sandbox/index.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,50 @@ async function testPreExistingOAuthTokens() {
9090
}
9191
}
9292

93+
async function testGroupsSupervisors() {
94+
console.log('\n=== Scenario 5: Test groups.getSupervisors ===');
95+
const { hostname, username, password } = config.basicAuth;
96+
if (!hostname || !username || !password) {
97+
console.warn(
98+
'[WARNING] groups.getSupervisors: Skipped (missing hostname, username, or password)',
99+
);
100+
return;
101+
}
102+
try {
103+
const xm = new XmApi(config.basicAuth);
104+
// First, get a list of groups to find one we can test with
105+
const groupsResponse = await xm.groups.get({ query: { limit: 1 } });
106+
console.log(
107+
'[INFO] groups.getSupervisors: Found groups:',
108+
groupsResponse.status,
109+
groupsResponse.body,
110+
);
111+
112+
if (groupsResponse.body.data && groupsResponse.body.data.length > 0) {
113+
const firstGroup = groupsResponse.body.data[0];
114+
const groupId = firstGroup.id || firstGroup.targetName;
115+
console.log(`[INFO] groups.getSupervisors: Testing with group: ${groupId}`);
116+
117+
const supervisorsResponse = await xm.groups.getSupervisors(groupId, { query: { limit: 5 } });
118+
console.log(
119+
'[SUCCESS] groups.getSupervisors:',
120+
supervisorsResponse.status,
121+
supervisorsResponse.body,
122+
);
123+
} else {
124+
console.log('[INFO] groups.getSupervisors: No groups found to test with');
125+
}
126+
} catch (err) {
127+
printError('[ERROR] groups.getSupervisors:', err);
128+
}
129+
}
130+
93131
// Run all scenarios sequentially
94132
await testBasicAuthOnly();
95133
await testOauthViaBasicAuthWithExplicitClientId();
96134
await testPasswordGrantWithDiscovery();
97135
await testPreExistingOAuthTokens();
136+
await testGroupsSupervisors();
98137

99138
function printError(context: string, err: unknown) {
100139
if (err instanceof Error) {

src/endpoints/groups/index.test.ts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ const mockSingleGroupBody = {
2323
created: '2025-01-01T00:00:00.000Z',
2424
};
2525

26+
const mockSinglePersonBody = {
27+
id: 'test-person-id',
28+
targetName: 'jdoe',
29+
firstName: 'John',
30+
lastName: 'Doe',
31+
recipientType: 'PERSON',
32+
status: 'ACTIVE',
33+
created: '2025-01-01T00:00:00.000Z',
34+
};
35+
2636
const mockPaginatedGroupsBody = {
2737
count: 1,
2838
total: 1,
@@ -32,6 +42,15 @@ const mockPaginatedGroupsBody = {
3242
},
3343
};
3444

45+
const mockPaginatedPeopleBody = {
46+
count: 1,
47+
total: 1,
48+
data: [mockSinglePersonBody],
49+
links: {
50+
self: '/api/xm/1/groups/test-group-id/supervisors?limit=100&offset=0',
51+
},
52+
};
53+
3554
Deno.test('GroupsEndpoint', async (t) => {
3655
await t.step('get() - List Groups', async (t) => {
3756
await t.step('makes GET request without parameters', async () => {
@@ -354,6 +373,85 @@ Deno.test('GroupsEndpoint', async (t) => {
354373
});
355374
});
356375

376+
await t.step('getSupervisors() - Get Group Supervisors', async (t) => {
377+
await t.step('makes GET request with group ID', async () => {
378+
mockHttpClient.setReqRes([{
379+
expectedRequest: {
380+
method: 'GET',
381+
url: 'https://test.xmatters.com/api/xm/1/groups/test-group-id/supervisors',
382+
headers: TestConstants.BASIC_AUTH_HEADERS,
383+
},
384+
mockedResponse: {
385+
status: 200,
386+
headers: { 'content-type': 'application/json' },
387+
body: mockPaginatedPeopleBody,
388+
},
389+
}]);
390+
await groups.getSupervisors('test-group-id');
391+
});
392+
393+
await t.step('makes GET request with group targetName', async () => {
394+
mockHttpClient.setReqRes([{
395+
expectedRequest: {
396+
method: 'GET',
397+
url: 'https://test.xmatters.com/api/xm/1/groups/Oracle Administrators/supervisors',
398+
headers: TestConstants.BASIC_AUTH_HEADERS,
399+
},
400+
mockedResponse: {
401+
status: 200,
402+
headers: { 'content-type': 'application/json' },
403+
body: mockPaginatedPeopleBody,
404+
},
405+
}]);
406+
await groups.getSupervisors('Oracle Administrators');
407+
});
408+
409+
await t.step('makes GET request with custom headers', async () => {
410+
mockHttpClient.setReqRes([{
411+
expectedRequest: {
412+
method: 'GET',
413+
url: 'https://test.xmatters.com/api/xm/1/groups/test-group-id/supervisors',
414+
headers: {
415+
...TestConstants.BASIC_AUTH_HEADERS,
416+
'X-Custom-Header': 'custom-value',
417+
},
418+
},
419+
mockedResponse: {
420+
status: 200,
421+
headers: { 'content-type': 'application/json' },
422+
body: mockPaginatedPeopleBody,
423+
},
424+
}]);
425+
await groups.getSupervisors('test-group-id', {
426+
headers: {
427+
'X-Custom-Header': 'custom-value',
428+
},
429+
});
430+
});
431+
432+
await t.step('makes GET request with query parameters', async () => {
433+
mockHttpClient.setReqRes([{
434+
expectedRequest: {
435+
method: 'GET',
436+
url:
437+
'https://test.xmatters.com/api/xm/1/groups/test-group-id/supervisors?limit=5&offset=10',
438+
headers: TestConstants.BASIC_AUTH_HEADERS,
439+
},
440+
mockedResponse: {
441+
status: 200,
442+
headers: { 'content-type': 'application/json' },
443+
body: mockPaginatedPeopleBody,
444+
},
445+
}]);
446+
await groups.getSupervisors('test-group-id', {
447+
query: {
448+
limit: 5,
449+
offset: 10,
450+
},
451+
});
452+
});
453+
});
454+
357455
await t.step('delete() - Delete Group', async (t) => {
358456
await t.step('makes DELETE request with group ID', async () => {
359457
mockHttpClient.setReqRes([{

0 commit comments

Comments
 (0)