Skip to content

Commit

Permalink
chore: add test workflow to gh actions
Browse files Browse the repository at this point in the history
add unit test for getProcessData
add unit test for getGenerateSocketData
  • Loading branch information
JS-AK committed Feb 2, 2023
1 parent 7ddde70 commit 9921e7a
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/jekyll-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
name: Deploy Jekyll with GitHub Pages dependencies preinstalled

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]
workflow_run:
workflows: ["Make release"]
branches: [ master ]
types:
- completed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -23,6 +25,7 @@ concurrency:
jobs:
# Build job
build:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Lint Runner
name: Lint & Test Runner

on:
push:
branches: [ master ]
Expand All @@ -18,3 +19,6 @@ jobs:

- name: Run ESLint
run: npm run lint

- name: Run Tests
run: npm test
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Make release

on:
workflow_run:
workflows: ["Lint Runner"]
workflows: ["Lint & Test Runner"]
branches: [ master ]
types:
- completed
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"build": "tsc",
"doc": "typedoc src/index.ts",
"lint": "eslint . --ext .ts",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npm run build && node ./build/test/index.js"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/test/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./unit/index.js";
84 changes: 84 additions & 0 deletions src/test/unit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import assert from "node:assert";
import test from "node:test";

import { AsteriskAmiAdapter } from "../..";

const amiAdapter = new AsteriskAmiAdapter();

test("Main checks", async (t) => {
await t.test("prepare data event from ami", async () => {
const reference = {
Action: "Originate",
ActionID: "76d0392a-b397-463f-a9fc-cc5ee49e0839",
Async: "true",
Channel: "Local/s@callback_op/n",
Context: "callback_op-ext",
Exten: "79000000000",
Priority: "1",
Variable: {
CALL_DST: "78000000000",
CALL_ID: "76d0392a-b397-463f-a9fc-cc5ee49e0839",
CALL_QUEUE: "aa0f3f8e-87a7-4ec6-9ad5-673e90de057f",
CALL_SRC: "79000000000",
COMP_ID: "1f4d3f81-544c-ffc2-a798-074b23fb42db",
},
};

let payload = "Action: Originate\r\n";

payload += "ActionID: 76d0392a-b397-463f-a9fc-cc5ee49e0839\r\n";
payload += "Async: true\r\n";
payload += "Channel: Local/s@callback_op/n\r\n";
payload += "Context: callback_op-ext\r\n";
payload += "Exten: 79000000000\r\n";
payload += "Priority: 1\r\n";
payload += "Variable: CALL_DST=78000000000\r\n";
payload += "Variable: CALL_ID=76d0392a-b397-463f-a9fc-cc5ee49e0839\r\n";
payload += "Variable: CALL_QUEUE=aa0f3f8e-87a7-4ec6-9ad5-673e90de057f\r\n";
payload += "Variable: CALL_SRC=79000000000\r\n";
payload += "Variable: COMP_ID=1f4d3f81-544c-ffc2-a798-074b23fb42db\r\n\r\n";

const result = amiAdapter.getProcessData(payload)[0];

assert.equal(JSON.stringify(reference), JSON.stringify(result));
});

await t.test("prepare data to ami", async () => {
let reference = "Action: Originate\r\n";

reference += "ActionID: 76d0392a-b397-463f-a9fc-cc5ee49e08399\r\n";
reference += "Async: true\r\n";
reference += "Channel: Local/s@callback_op/n\r\n";
reference += "Context: callback_op-ext\r\n";
reference += "Exten: 79000000000\r\n";
reference += "Priority: 1\r\n";
reference += "Variable: CALL_DST=78000000000\r\n";
reference += "Variable: CALL_ID=76d0392a-b397-463f-a9fc-cc5ee49e0839\r\n";
reference += "Variable: CALL_POSITION=1\r\n";
reference += "Variable: CALL_QUEUE=16d0392a-b391-463f-a9fc-cc5ee49e0839\r\n";
reference += "Variable: CALL_SRC=79000000000\r\n";
reference += "Variable: COMP_ID=1f4d3f81-544c-ffc2-a798-074b23fb42db\r\n\r\n";

const payload = {
Action: "Originate",
ActionID: "76d0392a-b397-463f-a9fc-cc5ee49e08399",
Async: "true",
Channel: "Local/s@callback_op/n",
Context: "callback_op-ext",
Exten: "79000000000",
Priority: "1",
Variable: [
"CALL_DST=78000000000",
"CALL_ID=76d0392a-b397-463f-a9fc-cc5ee49e0839",
"CALL_POSITION=1",
"CALL_QUEUE=16d0392a-b391-463f-a9fc-cc5ee49e0839",
"CALL_SRC=79000000000",
"COMP_ID=1f4d3f81-544c-ffc2-a798-074b23fb42db",
],
};

const result = amiAdapter.getGenerateSocketData(payload);

assert.equal(JSON.stringify(reference), JSON.stringify(result));
});
});

0 comments on commit 9921e7a

Please sign in to comment.