diff --git a/.husky/pre-commit b/.husky/pre-commit index 4ab7a70..5c48f8c 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -7,39 +7,39 @@ npx lint-staged echo "๐Ÿงช Running tests..." npm test -# # Run Spectral linting on Postman collections if they changed -# if git diff --cached --name-only | grep -qE "postman/collections/"; then -# echo "๐Ÿ“‹ Linting Postman collections with Spectral..." -# node .spectral/lint-with-names.js +# Run Spectral linting on Postman collections if they changed +if git diff --cached --name-only | grep -qE "postman/collections/"; then + echo "๐Ÿ“‹ Linting Postman collections with Spectral..." + node .spectral/lint-with-names.js -# if [ $? -ne 0 ]; then -# echo "โŒ Spectral linting failed for Postman collections" -# exit 1 -# fi + if [ $? -ne 0 ]; then + echo "โŒ Spectral linting failed for Postman collections" + exit 1 + fi -# echo "โœ… Postman collection linting passed!" -# fi + echo "โœ… Postman collection linting passed!" +fi -# # Run Postman tests only if Postman collection files changed -# if git diff --cached --name-only | grep -qE "postman/"; then -# echo "๐Ÿ“ฌ Postman collection changed - Running Postman tests..." +# Run Postman tests only if Postman collection files changed +if git diff --cached --name-only | grep -qE "postman/"; then + echo "๐Ÿ“ฌ Postman collection changed - Running Postman tests..." -# # Run all collections in postman/collections/ -# for collection in postman/collections/*.postman_collection.json; do -# if [ -f "$collection" ]; then -# echo " โ†’ Running: $(basename "$collection")" -# postman collection run "$collection" + # Run all collections in postman/collections/ + for collection in postman/collections/*.postman_collection.json; do + if [ -f "$collection" ]; then + echo " โ†’ Running: $(basename "$collection")" + postman collection run "$collection" -# if [ $? -ne 0 ]; then -# echo "โŒ Postman collection failed: $collection" -# exit 1 -# fi -# fi -# done + if [ $? -ne 0 ]; then + echo "โŒ Postman collection failed: $collection" + exit 1 + fi + fi + done -# echo "โœ… All Postman collections passed!" -# else -# echo "โญ๏ธ No Postman collection changes detected, skipping Postman tests" -# fi + echo "โœ… All Postman collections passed!" +else + echo "โญ๏ธ No Postman collection changes detected, skipping Postman tests" +fi echo "โœ… All pre-commit checks passed!" diff --git a/.postman/config.json b/.postman/config.json new file mode 100644 index 0000000..6159625 --- /dev/null +++ b/.postman/config.json @@ -0,0 +1,12 @@ +{ + "workspace": { + "id": "c9864502-aa44-4ebf-bebd-cc1186e4c94b" + }, + "entities": { + "collections": ["../postman/collections/Banking-API-Demo.postman_collection.json"], + "environments": [], + "specs": [], + "flows": [], + "globals": [] + } +} \ No newline at end of file diff --git a/postman/collections/Banking-API-Demo.postman_collection.json b/postman/collections/Banking-API-Demo.postman_collection.json new file mode 100644 index 0000000..5b1464f --- /dev/null +++ b/postman/collections/Banking-API-Demo.postman_collection.json @@ -0,0 +1,335 @@ +{ + "info": { + "_postman_id": "a8a8f3a3-0ffb-499d-90ce-4d050728c0d7", + "name": "Banking-API-Demo", + "description": "Collection generated from Banking-API-Demo Express routes", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "Admin", + "item": [ + { + "name": "Generate API Key", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "// Contract Test Script for Create Account POST request", + "pm.test(\"Status code is 201\", function () {", + " pm.response.to.have.status(200);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "url": { + "raw": "{{baseUrl}}/api/v1/auth", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "auth" + ] + } + } + } + ] + }, + { + "name": "Accounts", + "item": [ + { + "name": "List Accounts", + "request": { + "method": "GET", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/api/v1/accounts", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "accounts" + ] + } + } + }, + { + "name": "Create Account", + "request": { + "method": "POST", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"owner\": \"string\",\n \"balance\": 0,\n \"currency\": \"string\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/api/v1/accounts", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "accounts" + ] + } + } + }, + { + "name": "Get Account by ID", + "request": { + "method": "GET", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/api/v1/accounts/:accountId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "accounts", + ":accountId" + ], + "variable": [ + { + "key": "accountId" + } + ] + } + } + }, + { + "name": "Update Account", + "request": { + "method": "PATCH", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"owner\": \"string\",\n \"balance\": 0,\n \"currency\": \"string\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/api/v1/accounts/:accountId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "accounts", + ":accountId" + ], + "variable": [ + { + "key": "accountId" + } + ] + } + } + }, + { + "name": "Delete Account", + "request": { + "method": "DELETE", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/api/v1/accounts/:accountId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "accounts", + ":accountId" + ], + "variable": [ + { + "key": "accountId" + } + ] + } + } + } + ] + }, + { + "name": "Transactions", + "item": [ + { + "name": "List Transactions", + "request": { + "method": "GET", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/api/v1/transactions", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "transactions" + ] + } + } + }, + { + "name": "Create Transaction", + "request": { + "method": "POST", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"fromAccountId\": \"string\",\n \"toAccountId\": \"string\",\n \"amount\": 0,\n \"currency\": \"string\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/api/v1/transactions", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "transactions" + ] + } + } + }, + { + "name": "Get Transaction by ID", + "request": { + "method": "GET", + "header": [ + { + "key": "x-api-key", + "value": "{{apiKey}}", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/api/v1/transactions/:transactionId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "api", + "v1", + "transactions", + ":transactionId" + ], + "variable": [ + { + "key": "transactionId" + } + ] + } + } + } + ] + } + ], + "variable": [ + { + "key": "baseUrl", + "value": "", + "type": "default" + }, + { + "key": "apiKey", + "value": "" + } + ] +} \ No newline at end of file diff --git a/postman/globals/workspace.postman_globals.json b/postman/globals/workspace.postman_globals.json new file mode 100644 index 0000000..400e626 --- /dev/null +++ b/postman/globals/workspace.postman_globals.json @@ -0,0 +1,7 @@ +{ + "id": "d42f7dab-2e81-4572-87b1-b0e8f134f9f2", + "name": "Globals", + "values": [], + "_postman_variable_scope": "globals", + "_postman_exported_at": "2025-11-10T16:06:10.886Z" +} \ No newline at end of file