Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
env:
OFS_INSTANCE: ${{ secrets.OFS_INSTANCE }}
OFS_CLIENT_ID: ${{ secrets.OFS_CLIENT_ID }}
OFS_CLIENT_SECRET: ${{ secrets.OFS_CLIENT_SECRET }}
run: npm test

- name: Build
run: npm run build
20 changes: 20 additions & 0 deletions src/OFS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
OFSLastKnownPositionsResponse,
OFSGetSubmittedFormsParams,
OFSSubmittedFormsResponse,
OFSActivityLinkTypeResponse,
} from "./model";

export * from "./model";
Expand Down Expand Up @@ -456,6 +457,25 @@ export class OFS {
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
return this._get(partialURL);
}
/**
* Retrieve activities linked to an existing activity
* @param aid Activity id to retrieve linked activities for
*/
async getLinkedActivities(aid: number): Promise<OFSResponse> {
const partialURL = `/rest/ofscCore/v1/activities/${aid}/linkedActivities`;
return this._get(partialURL);
}

/**
* Retrieve the link type between two activities
* @param aid Activity id
* @param linkedActivityId Linked activity id
* @param linkType Type of link to retrieve
*/
async getActivityLinkType(aid: number, linkedActivityId: number, linkType: string): Promise<OFSActivityLinkTypeResponse> {
const partialURL = `/rest/ofscCore/v1/activities/${aid}/linkedActivities/${linkedActivityId}/linkTypes/${linkType}`;
return this._get(partialURL);
}
async updateActivity(aid: number, data: any): Promise<OFSResponse> {
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
return this._patch(partialURL, data);
Expand Down
26 changes: 26 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,32 @@ export class OFSActivityResponse extends OFSResponse {
};
}

export interface OFSLinkedActivitiesData {
totalResults: number;
items: ActivityResponse[];
links?: any;
}

export class OFSLinkedActivitiesResponse extends OFSResponse {
data: OFSLinkedActivitiesData = {
totalResults: 0,
items: [],
links: undefined,
};
}

export interface OFSActivityLinkTypeData {
linkType: string;
links?: any;
}

export class OFSActivityLinkTypeResponse extends OFSResponse {
data: OFSActivityLinkTypeData = {
linkType: '',
links: undefined
};
}

export class OFSPropertyDetailsResponse extends OFSResponse {
data: OFSPropertyDetails = {
label: "",
Expand Down
36 changes: 32 additions & 4 deletions test/general/core.activities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import { createReadStream, readFileSync } from "fs";
import { OFSCredentials, OFSBulkUpdateRequest } from "../../src/model";
import { OFS } from "../../src/OFS";
import myCredentials from "../credentials_test.json";
import { getTestCredentials } from "../test_credentials";
import { faker } from "@faker-js/faker";

var myProxy: OFS;

// Setup info
beforeAll(() => {
myProxy = new OFS(myCredentials);
if ("instance" in myCredentials) {
expect(myProxy.instance).toBe(myCredentials.instance);
const credentials = getTestCredentials();
myProxy = new OFS(credentials);
if ("instance" in credentials) {
expect(myProxy.instance).toBe(credentials.instance);
} else {
expect(myProxy.baseURL).toBe(myProxy.baseURL);
}
Expand Down Expand Up @@ -525,3 +526,30 @@ test("Get Submitted Forms with Real Data - Activity 3954799", async () => {
console.log('⚠ No submitted forms found for this activity');
}
});

test("Get Linked Activities for Activity", async () => {
var aid = 4225599; // sample activity id
var result = await myProxy.getLinkedActivities(aid);
// API may return 200 with an items array or 200 with empty result
expect(result.status).toBeGreaterThanOrEqual(200);
expect(result.status).toBeLessThan(400);
// If data contains items, ensure it's an array
if (result.data && result.data.items) {
expect(Array.isArray(result.data.items)).toBe(true);
}
});

test("Get Activity Link Type", async () => {
var aid = 4225599; // sample activity id
var linkedActivityId = 4225600; // sample linked activity id
var linkType = "requires"; // example link type
var result = await myProxy.getActivityLinkType(aid, linkedActivityId, linkType);
// API may return 200 with link type info
expect(result.status).toBeGreaterThanOrEqual(200);
expect(result.status).toBeLessThan(400);
// If successful response, check link type is returned
if (result.status === 200) {
expect(result.data).toHaveProperty('linkType');
expect(typeof result.data.linkType).toBe('string');
}
});
4 changes: 2 additions & 2 deletions test/general/core.resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/

import { OFSCredentials } from "../../src/model";
import { OFSCredentials, OFSBulkUpdateRequest } from "../../src/model";
import { OFS } from "../../src/OFS";
import myCredentials from "../credentials_test.json";
import { getTestCredentials } from "../test_credentials";

var myProxy: OFS;

Expand Down
21 changes: 21 additions & 0 deletions test/test_credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright © 2022, 2023, Oracle and/or its affiliates.
* Licensed under the Universal Permissive License (UPL), Version 1.0 as shown at https://oss.oracle.com/licenses/upl/
*/

import { OFSCredentials } from '../src/model';

export function getTestCredentials(): OFSCredentials {
const credentials: OFSCredentials = {
instance: process.env.OFS_INSTANCE || '',
clientId: process.env.OFS_CLIENT_ID || '',
clientSecret: process.env.OFS_CLIENT_SECRET || '',
};

if (!credentials.instance || !credentials.clientId || !credentials.clientSecret) {
console.warn('OFS test credentials not found in environment variables. Tests will fail.');
console.warn('Required environment variables: OFS_INSTANCE, OFS_CLIENT_ID, OFS_CLIENT_SECRET');
}

return credentials;
}
Loading