OmgImAlexis / astro

A torrent site mirroring tool
9 stars 3 forks source link

Adding tests for api #48

Open OmgImAlexis opened 7 years ago

OmgImAlexis commented 7 years ago

This should conclude with at least 80% coverage for the api routes.

OmgImAlexis commented 7 years ago
--------------------------------|----------|----------|----------|----------|----------------|
File                            |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
--------------------------------|----------|----------|----------|----------|----------------|
All files                       |     68.6 |    32.39 |    58.18 |       71 |                |
 app/config                     |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
 app/models                     |    90.91 |       50 |      100 |    90.91 |                |
  category.js                   |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
  torrent.js                    |    84.62 |       50 |      100 |    84.62 |          56,61 |
 app/routes                     |     46.4 |     6.32 |    42.11 |    49.57 |                |
  api.js                        |       50 |     5.26 |       40 |    53.57 |... 53,56,57,59 |
  category.js                   |    55.56 |        0 |    33.33 |     62.5 |       12,16,20 |
  core.js                       |    34.04 |     2.33 |    38.89 |     38.1 |... 2,95,96,102 |
  index.js                      |      100 |      100 |      100 |      100 |                |
  search.js                     |    23.81 |        0 |    33.33 |       25 |... 36,39,40,46 |
  settings.js                   |       80 |      100 |        0 |       80 |             10 |
  torrent.js                    |      100 |      100 |      100 |      100 |                |
 background                     |    91.67 |    83.33 |      100 |    91.67 |                |
  protocol.js                   |    91.67 |    83.33 |      100 |    91.67 |              9 |
 background/providers/rss/lib   |    94.59 |    91.43 |       75 |    94.44 |                |
  parse-feed.js                 |    94.59 |    91.43 |       75 |    94.44 |         47,112 |
 background/providers/rss/tests |    89.74 |      100 |      100 |    89.74 |                |
  generate-test-data.js         |    89.47 |      100 |      100 |    89.47 |  33,69,105,147 |
  testdata.js                   |      100 |      100 |      100 |      100 |                |
 utils                          |      100 |      100 |      100 |      100 |                |
  index.js                      |      100 |      100 |      100 |      100 |                |
--------------------------------|----------|----------|----------|----------|----------------|
OmgImAlexis commented 7 years ago

We should add to the docs under testing that res.send() should always be used for the API instead of res.json() as .json() expects an Accept header. Also .deepEquals(x, {}) is needed to test against empty objects and arrays instead of .is(x, {}).

OmgImAlexis commented 7 years ago

I'm really stumped now, half of the api tests seem to fail randomly and I can't workout where the race issue is since we use promises everywhere.. @aidanharris any ideas?

OmgImAlexis commented 7 years ago

Looks like the test "may" be failing because of a timeout which is caused by all the tests being scattered throughout the background dir.

For example yarn ava test passes 50% of the time for me yet running yarn test I end up with at least 1 test failing and it's not always the same one.