goldbergyoni / goldbergyoni/nodejs-testing-best-practices

🔥 Challenge: Migration tests recipe

Open
#58 0 comments 0 reactions 0 assignees View on GitHub
experiment
Dominant language
JavaScript
Stars
4.4k
Forks
288
PR merge metrics
No merged PRs in 30d

Description

Intergation tests are powerful becuase they allow testing the dark parts of the engine. Migrations are one of the darkest corners.

Two proposed tests:

- Undo all migrations without failures - This proves that we can undo. But it doesn't promise anything about the logic
- Ensure that migration is logically correct - Assuming that in v0.1 the field order.hasSupportTickets is optional and for some records it is null. Then in v0.2 this field is mandatory + New logic is presented: If this field is true, an order can not be deleted. The migration should set all NULL fields to true. A Typical test will insert records where this field is set (not null), it not even possible to insert an empty hasSupportTickets column because v0.2 doesn't allow this. But, in production for some rows it's null as they were inserted previously!

We can test this with:

test('When older Order record exist with empty hasSupportTickets and trying to delete it, then deletion fails with HTTP 409', () => {

// Arrange

migrate the DB to v0.1
insert an order with empty hasSupportTickets
migrate the DB to v0.2

// Act
try to delete the order

// Assert
...
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.