feat(learn): Add Stock Price Checker tests (#39640)

* Add some tests

* More tests

* remove extraneous declaration

* Remove unneeded test string

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Nicholas Carrigan (he/him)
2020-11-04 09:37:27 -08:00
committed by GitHub
parent 56ad1c7d60
commit cf35d24311

View File

@ -29,19 +29,48 @@ tests:
assert(!/.*\/stock-price-checker\.freecodecamp\.rocks/.test(getUserInput('url')));
}
- text: Set the content security policies to only allow loading of scripts and CSS from your server.
testString: ''
testString: "async getUserInput => {
const data = await fetch(getUserInput('url') + '/_api/app-info');
const parsed = await data.json();
assert.isTrue(parsed.headers['content-security-policy'].includes('script-src \\'self\\''));
assert.isTrue(parsed.headers['content-security-policy'].includes('style-src \\'self\\''));
}
"
- text: I can GET /api/stock-prices with form data containing a Nasdaq stock ticker and receive back an object stockData.
testString: ''
testString: "async getUserInput => {
const data = await fetch(getUserInput('url') + '/api/stock-prices?stock=GOOG');
const parsed = await data.json();
assert.property(parsed, 'stockData');
}"
- text: In stockData, I can see the stock (the ticker as a string), price (decimal in string format), and likes (int).
testString: ''
testString: "async getUserInput => {
const data = await fetch(getUserInput('url') + '/api/stock-prices?stock=GOOG');
const parsed = await data.json();
const ticker = parsed.stockData;
assert.typeOf(ticker.price, 'number');
assert.typeOf(ticker.likes, 'number');
assert.typeOf(ticker.stock, 'string');
}"
- text: I can also pass along field like as true (boolean) to have my like added to the stock(s). Only 1 like per IP should be accepted.
testString: ''
- text: If I pass along 2 stocks, the return object will be an array with information about both stocks. Instead of likes, it will display rel_likes (the difference between the likes on both stocks) on both.
testString: ''
- text: 'A good way to receive current prices is through our stock price proxy (replacing ''GOOG'' with your stock symbol): https://stock-price-checker-proxy--freecodecamp.repl.co/v1/stock/GOOG/quote'
testString: ''
testString: "async getUserInput => {
const data = await fetch(getUserInput('url') + '/api/stock-prices?stock=GOOG&stock=MSFT');
const parsed = await data.json();
const ticker = parsed.stockData;
assert.typeOf(ticker, 'array');
assert.property(ticker[0], 'rel_likes');
assert.property(ticker[1], 'rel_likes');
}"
- text: All 5 functional tests are complete and passing.
testString: ''
testString: "async getUserInput => {
const tests = await fetch(getUserInput('url') + '/_api/get-tests');
const parsed = await tests.json();
assert.isTrue(parsed.length >= 5);
parsed.forEach(test => {
assert.equal(test.state, 'passed');
});
}"
```