Kuncie Backend Test
Have you shopped online? Let’s imagine that you need to build the checkout backend service that will support different promotions with the given inventory.
Build a checkout system with these items:
The system should have the following promotions:
- Each sale of a MacBook Pro comes with a free Raspberry Pi B
- Buy 3 Google Homes for the price of 2
- Buying more than 3 Alexa Speakers will have a 10% discount on all Alexa speakers
Example Scenarios:
- Scanned Items: MacBook Pro, Raspberry Pi B
- Scanned Items: Google Home, Google Home, Google Home
- Scanned Items: Alexa Speaker, Alexa Speaker, Alexa Speaker
Please write it in Golang or Node with a CI script that runs tests and produces a binary.
Finally, imagine that adding items to cart and checking out was a backend API. Please design a schema file for GraphQL on how you would do this.
Thank you for your time and we look forward to reviewing your solution. If you have any questions, please feel free to contact us. Please send us a link to your git repo.
Database Schema
Building and Running The App
Prerequisites:
Go 1.16.9
Docker
Docker Compose
Golang migrate (https://github.com/golang-migrate/migrate)
Step 1 Checkout
$ git clone https://github.com/handika/kuncie-takehome-test.git
$ cd kuncie-backend-test
Step 2 Start MySQL Service
$ docker-compose up
Step 3 Run Migration
$ migrate -database mysql://kuncie:kuncie@/kuncie_store -path ./sql up
Step 4 GraphiQL Playground
http://localhost:9090/
Step 5 Calling APIs
Scanned Items: MacBook Pro, Raspberry Pi B
mutation {
StoreTransaction(input: {user_id: 1, items: [{product_id: 2, qty: 1}, {product_id: 4, qty: 1}]})
}
Scanned Items: Google Home, Google Home, Google Home
mutation {
StoreTransaction(input: {user_id: 1, items: [{product_id: 1, qty: 3}]})
}
Scanned Items: Alexa Speaker, Alexa Speaker, Alexa Speaker
mutation {
StoreTransaction(input: {user_id: 1, items: [{product_id: 3, qty: 3}]})
}
Get Transaction
query {
GetTransactionByID(id: 1) {
id
date
grand_total
}
}
Testing App
go test ./... -cover -vet -all -v