|
1 | 1 | import { beforeAll, beforeEach, describe, expect, test } from "@jest/globals"; |
2 | 2 | import { NetworkAsCodeClient } from "../src"; |
3 | 3 | import { Device, DeviceIpv4Addr } from "../src/models/device"; |
| 4 | +import { ProxyAgent } from "proxy-agent"; |
| 5 | +import fetch from "node-fetch"; |
| 6 | +import "dotenv/config"; |
4 | 7 | import { QoDSession } from "../src/models/session"; |
5 | 8 |
|
6 | | -import { configureClient } from "./configClient"; |
| 9 | +import { configureClient, configureNotificationServerUrl } from "./configClient"; |
7 | 10 |
|
8 | 11 | let client: NetworkAsCodeClient; |
| 12 | +let notificationUrl: string; |
| 13 | +let agent : ProxyAgent |
9 | 14 |
|
10 | 15 | beforeAll(() => { |
11 | | - client = configureClient() |
| 16 | + client = configureClient(); |
| 17 | + notificationUrl = configureNotificationServerUrl(); |
| 18 | + agent = new ProxyAgent() |
12 | 19 | }); |
13 | 20 |
|
14 | 21 | describe("Qos", () => { |
@@ -224,19 +231,79 @@ describe("Qos", () => { |
224 | 231 | await session.deleteSession(); |
225 | 232 | }); |
226 | 233 |
|
227 | | - test("should create a session with notification url", async () => { |
| 234 | + test("should create and delete a session with notification url", async () => { |
228 | 235 | const session = await device.createQodSession("QOS_L", { |
229 | 236 | duration: 3600, |
230 | 237 | serviceIpv4: "5.6.7.8", |
231 | 238 | serviceIpv6: "2041:0000:140F::875B:131B", |
232 | | - notificationAuthToken: "c8974e592c2fa383d4a3960714", |
233 | | - notificationUrl: "https://example.com/notifications", |
| 239 | + notificationUrl: `${notificationUrl}/notify`, |
234 | 240 | }); |
235 | 241 |
|
236 | 242 | expect(session.status).toEqual("REQUESTED"); |
237 | 243 | 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); |
240 | 307 |
|
241 | 308 | test("should create a session with public and private ipv4", async () => { |
242 | 309 | device = client.devices.get({ |
|
0 commit comments