Git Product home page Git Product logo

express-tdd's Introduction

Express TDD

TODO

Create Test Cases for User, Product and Cart

POST/admin/login

admin login

Request Header

none

Request Body

email : [email protected]
password : adminganteng

Response(200)

{
  id: 1,
  username: admin,
  email: [email protected]
  access_token : "token string"
}

Response(400)

{
  message : "Wrong email/password"
}

Response(500)

{
  message : "Internal server error"
}

POST/register

Register

Request Header

none

Request Body

username  : icanq
email     : [email protected]
password  : okeoke

Response(201)

{
  id: 1,
  username: icanq,
  email: [email protected]
}

Response(400)

{
  message : "username taken",
  message : "Username is required, cannot be blank",
  message : "Email have been registered",
  message : "Password is required cannot be blank",
  message : "Password minimal 6 character",

}

Response(500)

{
  message : "Internal server error"
}

POST/login

login

Request Header

none

Request Body

email : [email protected]
password : okeoke

Response(200)

{
  access_token : "token string"
}

Response(404)

{
  message : 'Account not found'
}

Response(400)

{
  message : "Wrong email/password"
}

Response(500)

{
  message : "Internal server error"
}

POST /products

create product

Request Header

access_token : 'token string'

Request Body

{
  "name": "rendang daging mantap betul",
  "image_url": "https://www.kitchensanctuary.com/wp-content/uploads/2018/01/Beef-Rendang-square-FS-28.jpg",
  "price": 30000,
  "stock": 300,
}

Response(201)

{
    "id": 5,
    "name": "rendang daging mantap betul",
    "image_url": "https://www.kitchensanctuary.com/wp-content/uploads/2018/01/Beef-Rendang-square-FS-28.jpg",
    "price": 30000,
    "stock": 300,
    "UserId": 1,
    "updatedAt": "2020-12-18T02:45:27.504Z",
    "createdAt": "2020-12-18T02:45:27.504Z"
}

Response(401)

{
  message : 'login first'
}

Response(400)

{
  message : "Name is required, cannot be blank",
  message : "Name cannot be null",
  message : "ImageUrl is required, cannot be blank",
  message : "ImageUrl cannot be null",
  message : "Price is required, cannot be blank",
  message : "Price must be number",
  message : "Cannot set to minus",
  message : "Stock is required, cannot be blank",
  message : "Stock must be number",
  message : "Cannot set to minus",
}

Response(500)

{
  message : "Internal server error"
}

GET /products

fetch all products

Request Header

access_token : 'token string'

Request Body

{
  none
}

Response(200)

[
    {
        "id": 1,
        "name": "rendang rancak bana",
        "image_url": "https://asset.kompas.com/crops/gi24VPQMhftubxYIWPJATjHrxTA=/0x0:1000x667/750x500/data/photo/2020/06/30/5efb0cb4a0226.jpg",
        "price": 125000,
        "stock": 200,
        "UserId": 1,
        "createdAt": "2020-12-12T09:20:38.587Z",
        "updatedAt": "2020-12-12T09:20:49.098Z"
    },
    {
        "id": 2,
        "name": "nasi daging enak pokoknya",
        "image_url": "https://i0.wp.com/www.pesenmakan.id/wp-content/uploads/2020/02/makanan-enak-di-jakarta-3.jpg?resize=696%2C696&ssl=1",
        "price": 20000,
        "stock": 333,
        "UserId": 1,
        "createdAt": "2020-12-12T16:16:25.240Z",
        "updatedAt": "2020-12-12T16:16:36.714Z"
    },
    {
        "id": 4,
        "name": "Sandal Baginda",
        "image_url": "https://www.static-src.com/wcsstore/Indraprastha/images/catalog/full//85/MTA-2825131/swallow_swallow-sandal-jepit-original_full03.jpg",
        "price": 10000,
        "stock": 5,
        "UserId": 1,
        "createdAt": "2020-12-15T02:41:31.458Z",
        "updatedAt": "2020-12-15T02:41:50.408Z"
    },
    {
        "id": 5,
        "name": "rendang daging mantap betul",
        "image_url": "https://www.kitchensanctuary.com/wp-content/uploads/2018/01/Beef-Rendang-square-FS-28.jpg",
        "price": 30000,
        "stock": 300,
        "UserId": 1,
        "createdAt": "2020-12-18T02:45:27.504Z",
        "updatedAt": "2020-12-18T02:45:27.504Z"
    }
]

Response(500)

{
  message : "Internal server error"
}

GET /products/:id

find by id

Request Header

access_token : 'token string'

Request Body

{
  none
}

Request Params

{
  id : 2
}

Response(200)

{
    "id": 2,
    "name": "nasi daging enak pokoknya",
    "image_url": "https://i0.wp.com/www.pesenmakan.id/wp-content/uploads/2020/02/makanan-enak-di-jakarta-3.jpg?resize=696%2C696&ssl=1",
    "price": 20000,
    "stock": 333,
    "UserId": 1,
    "createdAt": "2020-12-12T16:16:25.240Z",
    "updatedAt": "2020-12-12T16:16:36.714Z"
}

Response(500)

{
  message : "Internal server error"
}

put /products/:id

edit product

Request Header

access_token : 'token string'

Request Params

id : 2

Request Body

{
  "name"      : "nasi kapau",
  "image_url" : "https://i0.wp.com/www.pesenmakan.id/wp-content/uploads/2020/02/makanan-enak-di-jakarta-3.jpg?resize=696%2C696&ssl=1",
  "price"     : 40000,
  "stock"     : 3000,
}

Response(200)

{
    "id": 2,
    "name": "nasi daging enak pokoknya",
    "image_url": "https://i0.wp.com/www.pesenmakan.id/wp-content/uploads/2020/02/makanan-enak-di-jakarta-3.jpg?resize=696%2C696&ssl=1",
    "price": 20000,
    "stock": 333,
    "UserId": 1,
    "createdAt": "2020-12-12T16:16:25.240Z",
    "updatedAt": "2020-12-12T16:16:36.714Z"
}

Response(404)

{
  "message": "Product not found"
}

Response(401)

{
  "message": "login first"
}

Response(401)

{
  "message": "Unauthorized"
}

Response(400)

{
  "message": [
    "Name is required, cannot be blank",
    "Name cannot be null",
    "ImageUrl is required, cannot be blank",
    "ImageUrl cannot be null",
    "Price is required, cannot be blank",
    "Price must be number",
    "Cannot set to minus",
    "Stock is required, cannot be blank",
    "Stock must be number",
    "Cannot set to minus",
  ]
}

delete /products/:id

delete product

Request Header

access_token : 'token string'

Request Params

id : 3

Request Body

{
  none
}

Response(200)

{
  "message": "Succesfully deleted"
}

Response(401)

{
  "message": "login first"
}

Response(401)

{
  "message": "Unauthorized"
}

POST /cart

create or edit a cart for customer

Request Header

access_token: 'token string'

Request Body

ProductId: integer

Response(201)

{
  "Cart": {
    "id": 11,
    "ProductId": 5,
    "UserId": 3,
    "quantity": 1,
    "Status": false,
    "updatedAt": "2020-12-18T02:58:22.117Z",
    "createdAt": "2020-12-18T02:58:22.117Z"
  }
}

Response(200)

{
  "Cart": {
    "id": 11,
    "ProductId": 5,
    "UserId": 3,
    "quantity": 2,
    "Status": false,
    "updatedAt": "2020-12-18T02:58:22.117Z",
    "createdAt": "2020-12-18T02:58:22.117Z"
  }
}

Response(401)

{
  message: 'lack of stock'
}

Response(500)

{
  message: 'Internal server error'
}

GET /cart

fetch all carts with status false(unpaid)

Request Header

access_token: 'string'

Request Body

none

Response(200)

{
    "data": [
        {
            "id": 2,
            "ProductId": 2,
            "UserId": 1,
            "quantity": 5,
            "Status": false,
            "createdAt": "2020-12-17T04:46:10.299Z",
            "updatedAt": "2020-12-17T05:50:24.331Z",
            "Product": {
                "id": 2,
                "name": "nasi daging enak pokoknya",
                "image_url": "https://i0.wp.com/www.pesenmakan.id/wp-content/uploads/2020/02/makanan-enak-di-jakarta-3.jpg?resize=696%2C696&ssl=1",
                "price": 20000,
                "stock": 333,
                "UserId": 1,
                "createdAt": "2020-12-12T16:16:25.240Z",
                "updatedAt": "2020-12-12T16:16:36.714Z"
            }
        },
        {
            "id": 1,
            "ProductId": 1,
            "UserId": 1,
            "quantity": 1,
            "Status": false,
            "createdAt": "2020-12-17T04:45:50.940Z",
            "updatedAt": "2020-12-17T07:07:13.826Z",
            "Product": {
                "id": 1,
                "name": "rendang rancak bana",
                "image_url": "https://asset.kompas.com/crops/gi24VPQMhftubxYIWPJATjHrxTA=/0x0:1000x667/750x500/data/photo/2020/06/30/5efb0cb4a0226.jpg",
                "price": 125000,
                "stock": 200,
                "UserId": 1,
                "createdAt": "2020-12-12T09:20:38.587Z",
                "updatedAt": "2020-12-12T09:20:49.098Z"
            }
        }
    ],
    "totalPrice": 225000
}

Response(500)

{
  message: 'internal server error'
}

DELETE /cart/

delete a cart for customer

Request Header

access_token: 'string'

Request Body

cartId

Response(200)

{
  message: 'remove product from cart succeed'
}

Response(500)

{
  message: 'Internal server error'
}

POST /cart/checkout

checkout all active cart for customer

Request Header

access_token: 'string'

Request Body

none

Response(200)

{
  message: "checkout success"
}

Response(400)

{
  message: "Internal server error"
}

express-tdd's People

Contributors

icanq avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.