Skip to content

Commit d47d4e2

Browse files
committed
Merge branch 'qod-notify-tests' into 'release-25.4'
qod notification tests See merge request nwac/sdk-ts!97
2 parents 5d7bb4e + 404b3cf commit d47d4e2

File tree

1 file changed

+74
-7
lines changed

1 file changed

+74
-7
lines changed

integration-tests/qos.itest.ts

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { beforeAll, beforeEach, describe, expect, test } from "@jest/globals";
22
import { NetworkAsCodeClient } from "../src";
33
import { Device, DeviceIpv4Addr } from "../src/models/device";
4+
import { ProxyAgent } from "proxy-agent";
5+
import fetch from "node-fetch";
6+
import "dotenv/config";
47
import { QoDSession } from "../src/models/session";
58

6-
import { configureClient } from "./configClient";
9+
import { configureClient, configureNotificationServerUrl } from "./configClient";
710

811
let client: NetworkAsCodeClient;
12+
let notificationUrl: string;
13+
let agent : ProxyAgent
914

1015
beforeAll(() => {
11-
client = configureClient()
16+
client = configureClient();
17+
notificationUrl = configureNotificationServerUrl();
18+
agent = new ProxyAgent()
1219
});
1320

1421
describe("Qos", () => {
@@ -224,19 +231,79 @@ describe("Qos", () => {
224231
await session.deleteSession();
225232
});
226233

227-
test("should create a session with notification url", async () => {
234+
test("should create and delete a session with notification url", async () => {
228235
const session = await device.createQodSession("QOS_L", {
229236
duration: 3600,
230237
serviceIpv4: "5.6.7.8",
231238
serviceIpv6: "2041:0000:140F::875B:131B",
232-
notificationAuthToken: "c8974e592c2fa383d4a3960714",
233-
notificationUrl: "https://example.com/notifications",
239+
notificationUrl: `${notificationUrl}/notify`,
234240
});
235241

236242
expect(session.status).toEqual("REQUESTED");
237243
expect(session.profile).toEqual("QOS_L");
238-
await session.deleteSession();
239-
});
244+
245+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
246+
let notification = await fetch(`${notificationUrl}/qod/get/${session.id}`,
247+
{
248+
method: "GET",
249+
agent: agent
250+
});
251+
252+
const data = (await notification.json()) as any[];
253+
expect(data).not.toBeNull();
254+
255+
const sessionInfo = data[0]
256+
expect(sessionInfo).toHaveProperty("data.sessionId")
257+
expect(sessionInfo).toHaveProperty("data.qosStatus")
258+
259+
session.deleteSession();
260+
261+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
262+
notification = await fetch(`${notificationUrl}/qod/delete/${session.id}`,
263+
{
264+
method: "DELETE",
265+
agent: agent
266+
});
267+
268+
const message = (await notification.json()) as any[]
269+
expect(message).toEqual([{'message': 'Notification deleted'}, 200])
270+
271+
},20 * 1000);
272+
273+
test("should change session status from deletion", async () => {
274+
const session = await device.createQodSession("QOS_L", {
275+
duration: 3600,
276+
serviceIpv4: "5.6.7.8",
277+
serviceIpv6: "2041:0000:140F::875B:131B",
278+
notificationUrl: `${notificationUrl}/notify`,
279+
});
280+
281+
expect(session.status).toEqual("REQUESTED");
282+
expect(session.profile).toEqual("QOS_L");
283+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
284+
285+
session.deleteSession();
286+
287+
await new Promise(resolve => setTimeout(resolve, 5 * 1000));
288+
let notification = await fetch(`${notificationUrl}/qod/get/${session.id}`,
289+
{
290+
method: "GET",
291+
agent: agent
292+
});
293+
294+
const data = (await notification.json()) as any[];
295+
expect(data).not.toBeNull();
296+
297+
const deletionInfo = data[1]
298+
expect(deletionInfo).toHaveProperty("data.statusInfo", "DELETE_REQUESTED")
299+
300+
notification = await fetch(`${notificationUrl}/qod/delete/${session.id}`,
301+
{
302+
method: "DELETE",
303+
agent: agent
304+
});
305+
306+
},20 * 1000);
240307

241308
test("should create a session with public and private ipv4", async () => {
242309
device = client.devices.get({

0 commit comments

Comments
 (0)