add snapshot tests for loadBodyName

this is setup for the next change, where we'll get to see how the query change affects the body name!
This commit is contained in:
Emi Matchu 2020-08-21 16:22:16 -07:00
parent 7b1d2d67f0
commit 9f3fe820c2
3 changed files with 1122 additions and 3 deletions

File diff suppressed because it is too large Load diff

View file

@ -20,12 +20,16 @@ beforeAll(() => {
});
});
afterEach(() => {
if (dbExecuteFn) {
dbExecuteFn.mockClear();
}
});
afterAll(() => {
if (db) {
db.end();
}
});
const getDbCalls = () => dbExecuteFn.mock.calls;
const getDbCalls = () => (dbExecuteFn ? dbExecuteFn.mock.calls : []);
// Add a new `expect(res).toHaveNoErrors()` to call after GraphQL calls!
expect.extend({

29
src/server/util.test.js Normal file
View file

@ -0,0 +1,29 @@
const gql = require("graphql-tag");
const { getDbCalls } = require("./query-tests/setup.js");
const connectToDb = require("./db");
const { loadBodyName } = require("./util");
describe("loadBodyName", () => {
it("returns placeholder string for 0", async () => {
const bodyName = await loadBodyName("0");
expect(bodyName).toEqual("All bodies");
expect(getDbCalls()).toEqual([]);
});
it("loads body name for all body IDs", async () => {
jest.setTimeout(60000);
const db = await connectToDb();
const [rows] = await db.query(
`SELECT DISTINCT body_id FROM pet_types ORDER BY body_id ASC`
);
const bodyIds = rows.map((r) => String(r["body_id"]));
const bodyNames = await Promise.all(
bodyIds.map((bodyId) => loadBodyName(bodyId, db).then((n) => [bodyId, n]))
);
expect(bodyNames).toMatchSnapshot();
});
});