Skip to content

Commit

Permalink
corrected prettier config
Browse files Browse the repository at this point in the history
  • Loading branch information
devinpearson committed Nov 2, 2023
1 parent 2b07424 commit 367beb0
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 68 deletions.
23 changes: 11 additions & 12 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,12 +19,12 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- run: npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
README.md
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
{
"name": "card-emu",
"name": "programmable-card-code-emulator",
"version": "1.0.0",
"main": "src/index.js",
"scripts": {
"test": "jest",
"format": "prettier --write src/**/*.js"
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write ."
},
"keywords": [],
"keywords": [
"investec",
"card",
"emulator",
"programmable banking",
"open banking",
"banking"
],
"author": "Devin Pearson",
"license": "MIT",
"description": "",
"description": "An emulator for the Programmable Card Code Lamda function",
"dependencies": {
"lodash": "^4.17.21",
"moment-mini": "^2.29.4",
"node-fetch": "^2.7.0",
"uuid": "^9.0.1"

},
"devDependencies": {
"jest": "^29.7.0",
Expand Down
7 changes: 7 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
arrowParens: "always",
printWidth: 100,
proseWrap: "never",
singleQuote: true,
trailingComma: "es5",
};
100 changes: 50 additions & 50 deletions tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const emu = require("../src/index");
const validator = require('validator');
const validator = require("validator");

test("create a transaction", () => {
let dateTime = new Date();
Expand Down Expand Up @@ -30,35 +30,35 @@ test("create a transaction", () => {
});

test("create execution item", () => {
let dateTime = new Date();
dateTime = dateTime.toISOString();
const executionItem = emu.createExecutionItem(
"before_transaction",
dateTime,
[["sample log"]]
);
expect(validator.isUUID(executionItem.executionId, 4)).toBe(true);
expect(validator.isUUID(executionItem.rootCodeFunctionId, 4)).toBe(true);
expect(executionItem.sandbox).toBe(true);
expect(executionItem.type).toBe("before_transaction");
expect(executionItem.authorizationApproved).toBe(null);
expect(executionItem.logs[0].createdAt).toBe(dateTime);
expect(executionItem.logs[0].level).toBe("info");
expect(executionItem.logs[0].content).toBe("sample log");
});
let dateTime = new Date();
dateTime = dateTime.toISOString();
const executionItem = emu.createExecutionItem(
"before_transaction",
dateTime,
[["sample log"]],
);
expect(validator.isUUID(executionItem.executionId, 4)).toBe(true);
expect(validator.isUUID(executionItem.rootCodeFunctionId, 4)).toBe(true);
expect(executionItem.sandbox).toBe(true);
expect(executionItem.type).toBe("before_transaction");
expect(executionItem.authorizationApproved).toBe(null);
expect(executionItem.logs[0].createdAt).toBe(dateTime);
expect(executionItem.logs[0].level).toBe("info");
expect(executionItem.logs[0].content).toBe("sample log");
});

test("run vm", async () => {
let dateTime = new Date();
dateTime = dateTime.toISOString();
const transaction = emu.transaction(
"ZAR",
1000,
"0000",
"Test Merchant",
"Test City",
"ZAF",
);
const code = `const beforeTransaction = async (authorization) => {
test("run vm", async () => {
let dateTime = new Date();
dateTime = dateTime.toISOString();
const transaction = emu.transaction(
"ZAR",
1000,
"0000",
"Test Merchant",
"Test City",
"ZAF",
);
const code = `const beforeTransaction = async (authorization) => {
console.log(authorization);
return true;
};
Expand All @@ -75,24 +75,24 @@ test("create execution item", () => {
console.log("afterDecline");
};
`;
const results = await emu.run(
JSON.stringify({"test": "value"}),
code,
transaction
);
expect(results[0].authorizationApproved).toBeNull();
expect(results[0].completedAt).toBe(dateTime);
expect(results[0].createdAt).toBe(dateTime);
expect(results[0].emailCount).toBe(0);
expect(validator.isUUID(results[0].executionId, 4)).toBe(true);
expect(results[0].logs[0].content).toBe(transaction);
expect(results[0].logs[0].createdAt).toBe(dateTime);
expect(results[0].logs[0].level).toBe("info");
expect(results[0].pushNotificationCount).toBe(0);
expect(validator.isUUID(results[0].rootCodeFunctionId, 4)).toBe(true);
expect(results[0].sandbox).toBe(true);
expect(results[0].smsCount).toBe(0);
expect(results[0].startedAt).toBe(dateTime);
expect(results[0].type).toBe("before_transaction");
expect(results[0].updatedAt).toBe(dateTime);
});
const results = await emu.run(
JSON.stringify({ test: "value" }),
code,
transaction,
);
expect(results[0].authorizationApproved).toBeNull();
expect(results[0].completedAt).toBe(dateTime);
expect(results[0].createdAt).toBe(dateTime);
expect(results[0].emailCount).toBe(0);
expect(validator.isUUID(results[0].executionId, 4)).toBe(true);
expect(results[0].logs[0].content).toBe(transaction);
expect(results[0].logs[0].createdAt).toBe(dateTime);
expect(results[0].logs[0].level).toBe("info");
expect(results[0].pushNotificationCount).toBe(0);
expect(validator.isUUID(results[0].rootCodeFunctionId, 4)).toBe(true);
expect(results[0].sandbox).toBe(true);
expect(results[0].smsCount).toBe(0);
expect(results[0].startedAt).toBe(dateTime);
expect(results[0].type).toBe("before_transaction");
expect(results[0].updatedAt).toBe(dateTime);
});

0 comments on commit 367beb0

Please sign in to comment.