EventHopper / EHServerSide

Server-Side functionality including REST API, hosting scripts & client-server modules
0 stars 0 forks source link

Test Setup for Unit/CI Tests & Model Type Fix #116

Closed kylermintah closed 4 years ago

kylermintah commented 4 years ago

Tests are now working on /users and /events 🥳

Resolves #115 (Jest & Supertest Configured for Unit Testing & CI) Fixes #92 (type errors in strongly typed models - see relevant commit)

Notes:

Jest provides unit testing capabilities including stubs and mock objects. Supertest provides endpoint testing capabilities. Tests are kept in directory __tests__ in root. Endpoint tests should run on a separate port (added TEST_PORT to .env.dist)

Useful Documentation Here:

Example of /users test:

it('Succeeds to get the users endpoint', async done => {
  // Sends GET Request to /test endpoint
  const res = await request.get(`/users?key=${KEY}`);
  expect(res.status).toBe(200);
  expect(res.body).toBeDefined();
  expect(getType(res.body)).toBe('array');
  done();
})

Example of /events test:

it('Succeeds to get events by location with lat/long', async done => {
  // Sends GET Request to /test endpoint
  const res = await request.get(`/events?
  index=location
  &lat=39.9594667
  &long=-75.2249542&key=**${KEY}**
  &query={"category":"Music"}
  &radius=2`);
  expect(res.status).toBe(200);
  expect(res.body).toBeDefined();
  done()
})
kylermintah commented 4 years ago

Ignore failing CI tests. Removed ava tests

kylermintah commented 4 years ago

Pushing yarn.lock for reasons stated in this StackOverflow post. We can discuss whether or not to remove.