{"id":20972426,"url":"https://github.com/roodbaraky/checkout-system","last_synced_at":"2025-07-21T08:33:24.456Z","repository":{"id":250197109,"uuid":"824665385","full_name":"Roodbaraky/checkout-system","owner":"Roodbaraky","description":"An implementation of the shopping cart kata as outlined by SpareRoom built using TypeScript, Node.js, Vitest.","archived":false,"fork":false,"pushed_at":"2024-08-02T16:45:16.000Z","size":145,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-13T08:34:11.188Z","etag":null,"topics":["api","e-commerce","integration-testing","javascript","nodejs","tdd","test-driven-development","typescript","unit-testing","vitest"],"latest_commit_sha":null,"homepage":"https://checkout-system.onrender.com/cart/total","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Roodbaraky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-05T16:27:08.000Z","updated_at":"2024-08-13T13:52:59.000Z","dependencies_parsed_at":"2025-03-13T08:39:25.173Z","dependency_job_id":null,"html_url":"https://github.com/Roodbaraky/checkout-system","commit_stats":null,"previous_names":["roodbaraky/checkout-system"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Roodbaraky/checkout-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roodbaraky%2Fcheckout-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roodbaraky%2Fcheckout-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roodbaraky%2Fcheckout-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roodbaraky%2Fcheckout-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Roodbaraky","download_url":"https://codeload.github.com/Roodbaraky/checkout-system/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roodbaraky%2Fcheckout-system/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266267291,"owners_count":23902334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","e-commerce","integration-testing","javascript","nodejs","tdd","test-driven-development","typescript","unit-testing","vitest"],"created_at":"2024-11-19T04:08:06.214Z","updated_at":"2025-07-21T08:33:24.437Z","avatar_url":"https://github.com/Roodbaraky.png","language":"TypeScript","readme":"# Checkout System API - SpareRoom\n\n\n\n## Contents\n- [Checkout System API - SpareRoom](#checkout-system-api---spareroom)\n  - [Contents](#contents)\n  - [Overview](#overview)\n  - [Installation](#installation)\n  - [Testing](#testing)\n  - [Usage](#usage)\n    - [Development](#development)\n    - [Production](#production)\n    - [Try it out](#try-it-out)\n  - [Functionality](#functionality)\n\n\n## Overview\nThis is a simple checkout system endpoint which handles various products and their respective prices, including special offers in accordance with the brief outlined [here](https://spareroom.github.io/recruitment/docs/cart-kata/):\n```https://spareroom.github.io/recruitment/docs/cart-kata/``` \n\n\n## Installation\nClone the repository via:\n```git clone https://github.com/Roodbaraky/checkout-system```\n\nInstall dependencies via:\n```npm install```\n\n## Testing\nTests can be run manually via:\n```npm test```\nOR\n```npm run watch```\nTo use the '--watch' flag with Vitest.\n\nTests will also run automatically on commit via Husky.\n\nFunctions were first unit tested in isolation and then integration tested via the controller using a mock server and posting example carts to the endpoint.\nVitest was used for its seamless compatibility with TypeScript and similarity with the Jest testing framework.\n\n## Usage\nCreate a .env file in the project directory with the desired port to run the server on:\n```\n//.env\nPORT=3001\n```\nIt will default to 3001 if absent.\n\n### Development\nRun the development server via:\n```npm run dev```\n\n\n### Production\nBuild for production:\n```npm run build```\nOR\n```npm run clean```\nTo use the \"--clean\" flag with tsc.\n\nThis will transpile TypeScript code to JavaScript and export to the dist folder.\nFrom here, run dist/app.js with a process manager of your choice e.g.:\n```pm2 start dist/app.js```\n\n### Try it out\nAlternatively, try out the deployed app here:\n```https://checkout-system.onrender.com/cart/total```\nand query via an API client of your choice e.g. Insomnia\n\n## Functionality\nThe solution uses an endpoint at ```/cart/total``` which takes a cart/basket request body via POST, iterates through the cart items and mutlipies special and unit prices by quantity appropriately and returns a cumulative total.\n\nExample request: \n```\n[\n    {\n      \"code\": \"A\",\n      \"quantity\": 3\n    },\n    {\n      \"code\": \"B\",\n      \"quantity\": 3\n    },\n    {\n      \"code\": \"C\",\n      \"quantity\": 1\n    },\n    {\n      \"code\": \"D\",\n      \"quantity\": 2\n    }\n  ]\n  ```\n\n  Example response:\n  ```\n  {\n    \"total\":284\n  }\n  ```\n\n  Errors:\n  ```\n{\n\t\"error\": \"Invalid cart data\"\n}\n  ```\n```\n{\n\t\"error\": \"Item/s not found\"\n}\n```\n\n\n\nIt is loosely organised in the MVC architecture pattern, with the itemsData being imported from a JSON file, mimicking a database, where items could be added / removed, prices changed and special price offers removed / altered to suit business needs.\n\nThe controller function ```getCartTotal``` takes the request and first validates the cart to ensure it contains data in the correct format via the ```validateCart``` function, so that the 'database' is not unnecessarily queried with invalid cart properties, extra properties, incorrect datatypes etc. If the cart fails, this function will throw an error and return an appropriate error message.\n\nIf the cart is valid it is passed to the ```calculateCartTotal``` function which iterates through the cart, returning the cumulative total. If at any point an item code which is not present in the 'database' is passed, it throws an appropriate error which is returned.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froodbaraky%2Fcheckout-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froodbaraky%2Fcheckout-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froodbaraky%2Fcheckout-system/lists"}