|
6 | 6 | import { createReadStream, readFileSync } from "fs"; |
7 | 7 | import { OFSCredentials, OFSBulkUpdateRequest } from "../../src/model"; |
8 | 8 | import { OFS } from "../../src/OFS"; |
9 | | -import myCredentials from "../credentials_test.json"; |
| 9 | +import { getTestCredentials } from "../test_credentials"; |
10 | 10 | import { faker } from "@faker-js/faker"; |
11 | 11 |
|
12 | 12 | var myProxy: OFS; |
13 | 13 |
|
14 | 14 | // Setup info |
15 | 15 | 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); |
19 | 20 | } else { |
20 | 21 | expect(myProxy.baseURL).toBe(myProxy.baseURL); |
21 | 22 | } |
@@ -327,11 +328,16 @@ test("Get Activities", async () => { |
327 | 328 | }); |
328 | 329 |
|
329 | 330 | test("Search for Activities", async () => { |
330 | | - var currentDate = new Date().toISOString().split("T")[0]; |
| 331 | + // Use a date range from last week to today |
| 332 | + const today = new Date(); |
| 333 | + const lastWeek = new Date(today); |
| 334 | + lastWeek.setDate(today.getDate() - 7); |
| 335 | + const dateFrom = lastWeek.toISOString().split("T")[0]; |
| 336 | + const dateTo = today.toISOString().split("T")[0]; |
331 | 337 | var result = await myProxy.searchForActivities( |
332 | 338 | { |
333 | | - dateFrom: currentDate, |
334 | | - dateTo: currentDate, |
| 339 | + dateFrom, |
| 340 | + dateTo, |
335 | 341 | searchForValue: "137165209", |
336 | 342 | searchInField: "apptNumber", |
337 | 343 | }, |
@@ -525,3 +531,40 @@ test("Get Submitted Forms with Real Data - Activity 3954799", async () => { |
525 | 531 | console.log('⚠ No submitted forms found for this activity'); |
526 | 532 | } |
527 | 533 | }); |
| 534 | + |
| 535 | +test("Get Linked Activities for Activity", async () => { |
| 536 | + var aid = 4225599; // sample activity id |
| 537 | + var result = await myProxy.getLinkedActivities(aid); |
| 538 | + // API may return 200 with an items array or 200 with empty result |
| 539 | + expect(result.status).toBeGreaterThanOrEqual(200); |
| 540 | + expect(result.status).toBeLessThan(400); |
| 541 | + // If data contains items, ensure it's an array |
| 542 | + if (result.data && result.data.items) { |
| 543 | + expect(Array.isArray(result.data.items)).toBe(true); |
| 544 | + } |
| 545 | +}); |
| 546 | + |
| 547 | +test("Get Activity Link Type", async () => { |
| 548 | + var aid = 3954794; // updated activity id |
| 549 | + // Get link templates to use a valid linkType |
| 550 | + var linkTemplatesResult = await myProxy.getLinkTemplates(); |
| 551 | + expect(linkTemplatesResult.status).toBe(200); |
| 552 | + expect(linkTemplatesResult.data.items.length).toBeGreaterThan(0); |
| 553 | + var linkType = linkTemplatesResult.data.items[0].linkType; |
| 554 | + // Get linked activities to use a valid linkedActivityId |
| 555 | + var linkedActivitiesResult = await myProxy.getLinkedActivities(aid); |
| 556 | + expect(linkedActivitiesResult.status).toBeGreaterThanOrEqual(200); |
| 557 | + expect(linkedActivitiesResult.status).toBeLessThan(400); |
| 558 | + var linkedActivityId = Array.isArray(linkedActivitiesResult.data.items) && linkedActivitiesResult.data.items.length > 0 |
| 559 | + ? linkedActivitiesResult.data.items[0].activityId |
| 560 | + : aid + 1; // fallback to next id if none found |
| 561 | + var result = await myProxy.getActivityLinkType(aid, linkedActivityId, linkType); |
| 562 | + // API may return 200 with link type info |
| 563 | + expect(result.status).toBeGreaterThanOrEqual(200); |
| 564 | + expect(result.status).toBeLessThan(400); |
| 565 | + // If successful response, check link type is returned |
| 566 | + if (result.status === 200) { |
| 567 | + expect(result.data).toHaveProperty('linkType'); |
| 568 | + expect(typeof result.data.linkType).toBe('string'); |
| 569 | + } |
| 570 | +}); |
0 commit comments