Skip to content

Commit e754f94

Browse files
committed
Added delete and testing
1 parent 4bab56a commit e754f94

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

src/OFS.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,40 @@ export class OFS {
211211
return fetchPromise;
212212
}
213213

214+
private _delete(partialURL: string): Promise<OFSResponse> {
215+
var theURL = new URL(partialURL, this._baseURL);
216+
var myHeaders = new Headers();
217+
myHeaders.append("Authorization", this.authorization);
218+
var requestOptions = {
219+
method: "DELETE",
220+
headers: myHeaders,
221+
};
222+
const fetchPromise = fetch(theURL, requestOptions)
223+
.then(async function (response) {
224+
// Your code for handling the data you get from the API
225+
if (response.status == 204) {
226+
return new OFSResponse(
227+
theURL,
228+
response.status,
229+
undefined,
230+
undefined
231+
);
232+
} else {
233+
return new OFSResponse(
234+
theURL,
235+
response.status,
236+
response.statusText,
237+
await response.json()
238+
);
239+
}
240+
})
241+
.catch((error) => {
242+
console.log("error", error);
243+
return new OFSResponse(theURL, -1);
244+
});
245+
return fetchPromise;
246+
}
247+
214248
// Core: Subscription Management
215249
async getSubscriptions(): Promise<OFSSubscriptionResponse> {
216250
const partialURL = "/rest/ofscCore/v1/events/subscriptions";
@@ -223,6 +257,11 @@ export class OFS {
223257
return this._post(partialURL, data);
224258
}
225259

260+
async deleteActivity(aid: number): Promise<OFSResponse> {
261+
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
262+
return this._delete(partialURL);
263+
}
264+
226265
async getActivityDetails(aid: number): Promise<OFSActivityResponse> {
227266
const partialURL = `/rest/ofscCore/v1/activities/${aid}`;
228267
return this._get(partialURL);

test/general/base.test.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@ import { OFSCredentials } from "../../src/model";
88
import { OFS } from "../../src/OFS";
99
import myCredentials from "../credentials_test.json";
1010

11-
const myProxy: OFS = new OFS(myCredentials);
11+
var myProxy: OFS;
1212

13-
test("Creation", () => {
14-
//const myProxy = new OFS(myCredentials);
13+
// Setup info
14+
beforeAll(() => {
15+
myProxy = new OFS(myCredentials);
1516
expect(myProxy.instance).toBe(myCredentials.instance);
1617
});
1718

19+
// Teardown info
20+
var activityList: number[] = [];
21+
afterAll(() => {
22+
activityList.forEach(async (aid) => {
23+
await myProxy.deleteActivity(aid);
24+
});
25+
});
26+
1827
test("Get Subscriptions", async () => {
1928
//const myProxy = new OFS(myCredentials);
2029
var result = await myProxy.getSubscriptions();
@@ -33,6 +42,33 @@ test("Get non valid Activity Details", async () => {
3342
expect(result.status).toBe(400);
3443
});
3544

45+
test("Create Activity", async () => {
46+
var activityData = {
47+
activityType: "01",
48+
resourceId: "FLUSA",
49+
};
50+
var result = await myProxy.createActivity(activityData);
51+
expect(result.status).toBe(201);
52+
expect(result.data.activityType).toBe(activityData.activityType);
53+
// For cleanup
54+
var activityId = result.data.activityId;
55+
activityList.push(activityId);
56+
});
57+
58+
test("Delete Activity", async () => {
59+
var activityData = {
60+
activityType: "01",
61+
resourceId: "FLUSA",
62+
};
63+
var result = await myProxy.createActivity(activityData);
64+
expect(result.status).toBe(201);
65+
expect(result.data.activityType).toBe(activityData.activityType);
66+
var activityId = result.data.activityId;
67+
activityList.push(activityId);
68+
var result = await myProxy.deleteActivity(activityId);
69+
expect(result.status).toBe(204);
70+
});
71+
3672
test("Update Activity Details", async () => {
3773
var aid = 3954799;
3874
var initialName = "Gizella Quintero";

0 commit comments

Comments
 (0)