Skip to content

Commit f57e682

Browse files
committed
feat: Add getLinkedActivities and getActivityLinkType methods
- Add new methods to retrieve linked activities and their link types - Add corresponding types for API responses - Add test cases with secure credential handling - Configure GitHub Actions workflow for tests
1 parent baf9ae3 commit f57e682

File tree

6 files changed

+134
-6
lines changed

6 files changed

+134
-6
lines changed

.github/workflows/test.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Use Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: '18.x'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run tests
26+
env:
27+
OFS_INSTANCE: ${{ secrets.OFS_INSTANCE }}
28+
OFS_CLIENT_ID: ${{ secrets.OFS_CLIENT_ID }}
29+
OFS_CLIENT_SECRET: ${{ secrets.OFS_CLIENT_SECRET }}
30+
run: npm test
31+
32+
- name: Build
33+
run: npm run build

src/OFS.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
OFSLastKnownPositionsResponse,
2525
OFSGetSubmittedFormsParams,
2626
OFSSubmittedFormsResponse,
27+
OFSActivityLinkTypeResponse,
2728
} from "./model";
2829

2930
export * from "./model";
@@ -456,6 +457,25 @@ export class OFS {
456457
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
457458
return this._get(partialURL);
458459
}
460+
/**
461+
* Retrieve activities linked to an existing activity
462+
* @param aid Activity id to retrieve linked activities for
463+
*/
464+
async getLinkedActivities(aid: number): Promise<OFSResponse> {
465+
const partialURL = `/rest/ofscCore/v1/activities/${aid}/linkedActivities`;
466+
return this._get(partialURL);
467+
}
468+
469+
/**
470+
* Retrieve the link type between two activities
471+
* @param aid Activity id
472+
* @param linkedActivityId Linked activity id
473+
* @param linkType Type of link to retrieve
474+
*/
475+
async getActivityLinkType(aid: number, linkedActivityId: number, linkType: string): Promise<OFSActivityLinkTypeResponse> {
476+
const partialURL = `/rest/ofscCore/v1/activities/${aid}/linkedActivities/${linkedActivityId}/linkTypes/${linkType}`;
477+
return this._get(partialURL);
478+
}
459479
async updateActivity(aid: number, data: any): Promise<OFSResponse> {
460480
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
461481
return this._patch(partialURL, data);

src/model.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,32 @@ export class OFSActivityResponse extends OFSResponse {
144144
};
145145
}
146146

147+
export interface OFSLinkedActivitiesData {
148+
totalResults: number;
149+
items: ActivityResponse[];
150+
links?: any;
151+
}
152+
153+
export class OFSLinkedActivitiesResponse extends OFSResponse {
154+
data: OFSLinkedActivitiesData = {
155+
totalResults: 0,
156+
items: [],
157+
links: undefined,
158+
};
159+
}
160+
161+
export interface OFSActivityLinkTypeData {
162+
linkType: string;
163+
links?: any;
164+
}
165+
166+
export class OFSActivityLinkTypeResponse extends OFSResponse {
167+
data: OFSActivityLinkTypeData = {
168+
linkType: '',
169+
links: undefined
170+
};
171+
}
172+
147173
export class OFSPropertyDetailsResponse extends OFSResponse {
148174
data: OFSPropertyDetails = {
149175
label: "",

test/general/core.activities.test.ts

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
import { createReadStream, readFileSync } from "fs";
77
import { OFSCredentials, OFSBulkUpdateRequest } from "../../src/model";
88
import { OFS } from "../../src/OFS";
9-
import myCredentials from "../credentials_test.json";
9+
import { getTestCredentials } from "../test_credentials";
1010
import { faker } from "@faker-js/faker";
1111

1212
var myProxy: OFS;
1313

1414
// Setup info
1515
beforeAll(() => {
16-
myProxy = new OFS(myCredentials);
17-
if ("instance" in myCredentials) {
18-
expect(myProxy.instance).toBe(myCredentials.instance);
16+
const credentials = getTestCredentials();
17+
myProxy = new OFS(credentials);
18+
if ("instance" in credentials) {
19+
expect(myProxy.instance).toBe(credentials.instance);
1920
} else {
2021
expect(myProxy.baseURL).toBe(myProxy.baseURL);
2122
}
@@ -525,3 +526,30 @@ test("Get Submitted Forms with Real Data - Activity 3954799", async () => {
525526
console.log('⚠ No submitted forms found for this activity');
526527
}
527528
});
529+
530+
test("Get Linked Activities for Activity", async () => {
531+
var aid = 4225599; // sample activity id
532+
var result = await myProxy.getLinkedActivities(aid);
533+
// API may return 200 with an items array or 200 with empty result
534+
expect(result.status).toBeGreaterThanOrEqual(200);
535+
expect(result.status).toBeLessThan(400);
536+
// If data contains items, ensure it's an array
537+
if (result.data && result.data.items) {
538+
expect(Array.isArray(result.data.items)).toBe(true);
539+
}
540+
});
541+
542+
test("Get Activity Link Type", async () => {
543+
var aid = 4225599; // sample activity id
544+
var linkedActivityId = 4225600; // sample linked activity id
545+
var linkType = "requires"; // example link type
546+
var result = await myProxy.getActivityLinkType(aid, linkedActivityId, linkType);
547+
// API may return 200 with link type info
548+
expect(result.status).toBeGreaterThanOrEqual(200);
549+
expect(result.status).toBeLessThan(400);
550+
// If successful response, check link type is returned
551+
if (result.status === 200) {
552+
expect(result.data).toHaveProperty('linkType');
553+
expect(typeof result.data.linkType).toBe('string');
554+
}
555+
});

test/general/core.resources.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
44
*/
55

6-
import { OFSCredentials } from "../../src/model";
6+
import { OFSCredentials, OFSBulkUpdateRequest } from "../../src/model";
77
import { OFS } from "../../src/OFS";
8-
import myCredentials from "../credentials_test.json";
8+
import { getTestCredentials } from "../test_credentials";
99

1010
var myProxy: OFS;
1111

test/test_credentials.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright © 2022, 2023, Oracle and/or its affiliates.
3+
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
4+
*/
5+
6+
import { OFSCredentials } from '../src/model';
7+
8+
export function getTestCredentials(): OFSCredentials {
9+
const credentials: OFSCredentials = {
10+
instance: process.env.OFS_INSTANCE || '',
11+
clientId: process.env.OFS_CLIENT_ID || '',
12+
clientSecret: process.env.OFS_CLIENT_SECRET || '',
13+
};
14+
15+
if (!credentials.instance || !credentials.clientId || !credentials.clientSecret) {
16+
console.warn('OFS test credentials not found in environment variables. Tests will fail.');
17+
console.warn('Required environment variables: OFS_INSTANCE, OFS_CLIENT_ID, OFS_CLIENT_SECRET');
18+
}
19+
20+
return credentials;
21+
}

0 commit comments

Comments
 (0)