From 215fb701ff07ce044679a4e0da0cad12d426d847 Mon Sep 17 00:00:00 2001 From: Gbadebo Bello Date: Tue, 4 Nov 2025 23:35:19 +0100 Subject: [PATCH 1/2] commit --- .husky/pre-commit | 56 ++--- .postman/config.json | 12 + ...rgalactic Bank API.postman_collection.json | 235 ++++++++++++++++++ .../globals/workspace.postman_globals.json | 7 + 4 files changed, 282 insertions(+), 28 deletions(-) create mode 100644 .postman/config.json create mode 100644 postman/collections/Intergalactic Bank API.postman_collection.json create mode 100644 postman/globals/workspace.postman_globals.json 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..ff3457d --- /dev/null +++ b/.postman/config.json @@ -0,0 +1,12 @@ +{ + "workspace": { + "id": "dc52c5c3-a708-487e-891e-3f0d62737b8c" + }, + "entities": { +6โ”‚ "collections": ["../postman/collections/Intergalactic Bank API.postman_collection.json"], + "environments": [], + "specs": [], + "flows": [], + "globals": [] + } +} \ No newline at end of file diff --git a/postman/collections/Intergalactic Bank API.postman_collection.json b/postman/collections/Intergalactic Bank API.postman_collection.json new file mode 100644 index 0000000..cb8cc51 --- /dev/null +++ b/postman/collections/Intergalactic Bank API.postman_collection.json @@ -0,0 +1,235 @@ +{ + "info": { + "_postman_id": "e435e6cd-fc60-4154-96db-7f876c3a45bb", + "name": "Intergalactic Bank API", + "description": "The Intergalactic Bank API makes it easy to manage transaction and account data. Features include Account Management, Transaction Processing, Multiple Currencies, API Key Authentication, and Rate Limiting.", + "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": [ + "pm.test(\"Extract and store API key\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('apiKey');", + " pm.collectionVariables.set('apiKey', jsonData.apiKey);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:3000/api/v1/auth", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "auth" + ] + }, + "description": "Generates a new API key for accessing the Intergalactic Bank API. This endpoint does not require authentication." + } + } + ] + }, + { + "name": "Accounts", + "item": [ + { + "name": "List all accounts", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:3000/api/v1/accounts?owner=Nova Newman&createdAt=2023-04-10", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "accounts" + ], + "query": [ + { + "key": "owner", + "value": "Nova Newman" + }, + { + "key": "createdAt", + "value": "2023-04-10" + } + ] + }, + "description": "Retrieves a list of all accounts at the Intergalactic Bank. Optionally filter by owner name or creation date." + } + }, + { + "name": "Create new account", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"owner\": \"Nova Newman\",\n \"balance\": 500,\n \"currency\": \"COSMIC_COINS\"\n}" + }, + "url": { + "raw": "http://localhost:3000/api/v1/accounts", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "accounts" + ] + }, + "description": "Creates a new account at the Intergalactic Bank. The account will be assigned a unique ID. The currency cannot be changed once the account is created." + } + } + ] + }, + { + "name": "Transactions", + "item": [ + { + "name": "List all transactions", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:3000/api/v1/transactions?fromAccountId=11111111&toAccountId=18974440&createdAt=2024-01-10", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "transactions" + ], + "query": [ + { + "key": "fromAccountId", + "value": "11111111" + }, + { + "key": "toAccountId", + "value": "18974440" + }, + { + "key": "createdAt", + "value": "2024-01-10" + } + ] + }, + "description": "Retrieves a list of transactions. Optionally filter by source account, destination account, or creation date." + } + }, + { + "name": "Create new transaction", + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"fromAccountId\": \"12345678\",\n \"toAccountId\": \"87654321\",\n \"amount\": 10000,\n \"currency\": \"COSMIC_COINS\"\n}" + }, + "url": { + "raw": "http://localhost:3000/api/v1/transactions", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "transactions" + ] + }, + "description": "Creates a new transaction. There are two types of transactions: Transfer and Deposit. Transactions cannot be edited or deleted once created." + } + }, + { + "name": "Get transaction by ID", + "request": { + "method": "GET", + "url": { + "raw": "http://localhost:3000/api/v1/transactions/{transactionId}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "3000", + "path": [ + "api", + "v1", + "transactions", + "{transactionId}" + ] + }, + "description": "Retrieves detailed information about a specific transaction by its ID." + } + } + ] + } + ], + "auth": { + "type": "apikey", + "apikey": [ + { + "key": "value", + "value": "{{apiKey}}", + "type": "string" + }, + { + "key": "key", + "value": "x-api-key", + "type": "string" + } + ] + }, + "variable": [ + { + "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..c11f27c --- /dev/null +++ b/postman/globals/workspace.postman_globals.json @@ -0,0 +1,7 @@ +{ + "id": "1fa9efaf-f1eb-4d4e-8fe4-94937789787a", + "name": "Globals", + "values": [], + "_postman_variable_scope": "globals", + "_postman_exported_at": "2025-11-04T22:21:28.930Z" +} \ No newline at end of file From ed481ec45199e24269ce45fbf9a3a1ca817864bd Mon Sep 17 00:00:00 2001 From: Gbadebo Bello Date: Tue, 4 Nov 2025 23:36:02 +0100 Subject: [PATCH 2/2] addeed a new route --- src/routes/accounts.js | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/routes/accounts.js b/src/routes/accounts.js index 6165297..e29f1c2 100644 --- a/src/routes/accounts.js +++ b/src/routes/accounts.js @@ -40,33 +40,33 @@ router.get('/', validateApiKey, (req, res) => { * GET /api/v1/accounts/:accountId * Get a specific account by ID */ -// router.get('/:accountId', validateApiKey, (req, res) => { -// try { -// const { accountId } = req.params; +router.get('/:accountId', validateApiKey, (req, res) => { + try { + const { accountId } = req.params; -// const account = db.getAccountById(accountId); + const account = db.getAccountById(accountId); -// if (!account) { -// return res.status(404).json({ -// error: { -// name: 'instanceNotFoundError', -// message: 'The specified account does not exist.' -// } -// }); -// } + if (!account) { + return res.status(404).json({ + error: { + name: 'instanceNotFoundError', + message: 'The specified account does not exist.' + } + }); + } -// res.status(200).json({ -// account: account.toJSON() -// }); -// } catch (error) { -// res.status(500).json({ -// error: { -// name: 'serverError', -// message: 'Failed to retrieve account' -// } -// }); -// } -// }); + res.status(200).json({ + account: account.toJSON() + }); + } catch (error) { + res.status(500).json({ + error: { + name: 'serverError', + message: 'Failed to retrieve account' + } + }); + } +}); /** * POST /api/v1/accounts