Lastly, for completeness, here are the end to end tests for our application endpoints. In case of any issues, you can refer to my Github repository here.
The main app e2e test mainly has some boilerplate code that comes by default when we generate our application.
When you run the tests they should pass:
npm run test:e2e app
Output:
> storefront-backend@0.0.1 test:e2e
> jest --config ./test/jest-e2e.json "app"
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 0ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
PASS test/app.e2e-spec.ts
AppController (e2e)
✓ / (GET)(34 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 4.004 s
Ran all test suites matching /app/i.
Auth e2e tests
We test our auth endpoints here. The describe blocks explain what the specs are meant to do:
> storefront-backend@0.0.1 test:e2e
> jest --config ./test/jest-e2e.json "auth"
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 64ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 58ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
PASS test/auth.e2e-spec.ts
AuthController (e2e)
when registering
and using valid data
✓ should respond with the customer data minus the password (103 ms)
✓ should throw an error when a duplicate user is registered (55 ms)
and using invalid data
✓ should throw an error (3 ms)
when logging in
and using valid data
✓ should respond with a success message (116 ms)
and using invalid data
✓ should respond with a bad request error message (3 ms)
when logging out
and using an invalid cookie
✓ should respond with an unauthorized message (2 ms)
when getting a refresh token
without a valid jwt token
✓ should respond with an unauthorized message (2 ms)
Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 4.869 s
Ran all test suites matching /auth/i.
Orders e2e tests
Here we start by mocking an auth guard as well as the expected results before calling the order controller endpoints:
> storefront-backend@0.0.1 test:e2e
> jest --config ./test/jest-e2e.json "orders"
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 1ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 0ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
PASS test/orders.e2e-spec.ts
OrdersController (e2e)
order creation
✓ returns an order object (34 ms)
stripe callback
✓ updates the order payment status via the webhook (4 ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 3.638 s
Ran all test suites matching /orders/i.
Products e2e tests
Lastly we test our products controller endpoints, using mocks where necessary:
> storefront-backend@0.0.1 test:e2e
> jest --config ./test/jest-e2e.json "products"
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 0ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 1ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 0ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
console.log
Before...
at LoggingInterceptor.intercept (../src/common/interceptors/logging.interceptor.ts:13:13)
console.log
After... 0ms
at Object.next (../src/common/interceptors/logging.interceptor.ts:18:31)
PASS test/products.e2e-spec.ts
ProductsController (e2e)
product creation
✓ returns a product object (98 ms)
find all products
✓ returns an array of products (5 ms)
updating a product
✓ returns an update result (8 ms)
deleting a product
✓ returns a delete result (3 ms)
Test Suites: 1 passed, 1 total
Tests: 4 passed, 4 total
Snapshots: 0 total
Time: 3.606 s
Ran all test suites matching /products/i.