Git Product home page Git Product logo

php-test-2021-10-08's Introduction

php-test-2021-10-08

How start the project

1.Install docker and docker-compose
2.Run these commands

# go to the root of the project where docker-compose.yml exist
docker-compose up -d
make init

3.Done ๐Ÿ˜Ž๐Ÿ”ฅ๐Ÿ”ฅ
Now you can use apis from this links
http://localhost:81/api/add-money and http://localhost:81/api/get-balance/1

Run behavioral tests ๐Ÿ”ฅ

I wrote some behavioral tests for the app, somethings like this ...

Scenario: Add money to ali's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  When Add 0 dollars to the user wallet with userId 1
  Then user with userId 1 should have 0 dollars more to the wallet

Scenario: Add money to ali's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  When Add 1 dollars to the user wallet with userId 1
  Then user with userId 1 should have 1 dollars more to the wallet

Scenario: Add money to ali's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  When Add 1 dollars to the user wallet with userId 1
  When Add -1 dollars to the user wallet with userId 1
  Then user with userId 1 should have 0 dollars more to the wallet

Scenario: Add money to ali's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  When Add 1 dollars to the user wallet with userId 1
  When Add -1 dollars to the user wallet with userId 1
  When Add 100 dollars to the user wallet with userId 1
  When Add 200 dollars to the user wallet with userId 1
  When Add -50 dollars to the user wallet with userId 1
  Then user with userId 1 should have 250 dollars more to the wallet

Scenario: Add money to ali's wallet and moahmmad's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  Given Get current wallet amout of user 2
  When Add 1 dollars to the user wallet with userId 1
  When Add -1 dollars to the user wallet with userId 1
  When Add 5 dollars to the user wallet with userId 2
  Then user with userId 1 should have 0 dollars more to the wallet
  Then user with userId 2 should have 5 dollars more to the wallet

Scenario: Add money to ali's wallet and moahmmad's wallet serveral times and check and money amout 
  Given Get current wallet amout of user 1
  Given Get current wallet amout of user 2
  When Add 1000 dollars to the user wallet with userId 1
  When Add -2000 dollars to the user wallet with userId 1
  When Add 100 dollars to the user wallet with userId 1
  When Add 5 dollars to the user wallet with userId 2
  When Add 55 dollars to the user wallet with userId 2
  Then user with userId 1 should have -900 dollars more to the wallet
  Then user with userId 2 should have 60 dollars more to the wallet

You can run this command for test the app with different scenarios

make test

And that will be the result

6 scenarios (6 passed)
33 steps (33 passed)
0m2.91s (11.53Mb)

Run the command for calc the total transaction amount (daily job)

You can run the command like this

make totalTransactionCalc

Result

Total amount of transactions is -668

And if you want to run it once every day you can just run this command

sudo crontab -e

And then add this line at the end of the file and that is all

0 0 * * * cd <make file path> ; make totalTransactionCalc

How send a request

add-money

You can send data to http://localhost:81/api/add-money with post method
Your request body should have amout (int) and user_id (int) fields
(send them in form-data)

get-balance

You can fetch http://localhost:81/api/get-balance/1 with get method
Your request should have user_id which is a url param and in this example we set it to 1

For testing the app manually you can use the add-money api to add the money to the use wallet and then with get balance api check the wallet

php-test-2021-10-08's People

Contributors

azibom avatar

Stargazers

 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.