Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mian-ali/challenge-ping-tree
This test is to build an API for the http server to receive POST requests with information about a visitor and respond with a decision, either: rejection, or accept with a corresponding target url.
https://github.com/mian-ali/challenge-ping-tree
api api-rest api-test challenge challenge-ping-tree nodejs
Last synced: about 8 hours ago
JSON representation
This test is to build an API for the http server to receive POST requests with information about a visitor and respond with a decision, either: rejection, or accept with a corresponding target url.
- Host: GitHub
- URL: https://github.com/mian-ali/challenge-ping-tree
- Owner: mian-ali
- License: mit
- Created: 2022-05-06T18:27:26.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-10T06:52:55.000Z (over 2 years ago)
- Last Synced: 2023-03-04T01:41:33.957Z (over 1 year ago)
- Topics: api, api-rest, api-test, challenge, challenge-ping-tree, nodejs
- Language: JavaScript
- Homepage:
- Size: 126 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
This test is to build an API for the http server to receive POST requests with information about a visitor and respond with a decision, either: rejection, or accept with a corresponding target url.
## Decisioning
1) The decisions should be based on information about the visitor that comes in POST request body
{
"geoState": "ca",
"publisher": "abc",
"timestamp": "2018-07-19T23:28:59.513Z"
}2) No `target` can receive more traffic per day than it allows. Here's an example `target` with max 10 accepts per day
{
"id": "1",
"url": "http://example.com",
"value": "0.50",
"maxAcceptsPerDay": "10",
"accept": {
"geoState": {
"$in": ["ca", "ny"]
},
"hour": {
"$in": [ "13", "14", "15" ]
}
}
}4) All remaining `targets` should be filtered by criteria they are willing to accept. The above `target` example only accepts visitors from either California or New York from 13 to 16 UTC.
5) If no `targets` are left, the request is rejected (returns `{"decision":"reject"}`), otherwise it should return the url of the remaining `target` with the highest value.
## Requirements
1. New endpoints that needs to be built:
- POST /api/targets
- post a target
- GET /api/targets
- get all targets
- GET /api/target/:id
- get a target by id
- POST /api/target/:id
- update a target by id
- POST /route
- post a request with information about the visitor
- respond with a decision2. API functional tests.
- each endpoint should have its own test
- write all tests in `test/endpoints.js`
- be sure to understand how [`servertest`](https://github.com/rvagg/servertest) worksAll persistence should use [redis](http://redis.io).
Source code should be in `lib` dir.
Use redis client factory from `lib/redis.js` and do not edit this file.## Instructions
How to attempt this test:
1. Create a new repo in your account and note the git url
2. Clone this repo
4. Set your new repo as the origin: `git remote set-url origin ${your repo url}`
5. Push your solution to your repoYou must follow these steps for your solution to be accepted -- forks or other methods will not be considered.