Skip to content

Commit 8e16dbf

Browse files
committed
Refactor update tests to handle optional chaining for updated post and user fields, ensuring robustness against null values.
1 parent fba3d9a commit 8e16dbf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

__tests__/repository/update.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ describe("Repository Update", () => {
4444
});
4545

4646
expect(updatedPost).toBeDefined();
47-
expect(updatedPost.title).toBe("Updated Title");
47+
expect(updatedPost?.title).toBe("Updated Title");
4848

4949
// Make sure also updated in the database
5050
const queryResult = await executor.executeSQL<DomainPost>(
5151
`SELECT * FROM posts WHERE id = $1`,
52-
[targetPost.id],
52+
[targetPost.id]
5353
);
5454
expect(queryResult.rows[0]).toBeDefined();
5555
expect(queryResult.rows[0]).toMatchObject({
@@ -67,13 +67,13 @@ describe("Repository Update", () => {
6767
},
6868
});
6969
expect(updatedUser).toBeDefined();
70-
expect(updatedUser.name).toBe("Updated Name");
71-
expect(updatedUser.age).toBe(30);
70+
expect(updatedUser?.name).toBe("Updated Name");
71+
expect(updatedUser?.age).toBe(30);
7272

7373
// Make sure also updated in the database
7474
const fetchedUser = await executor.executeSQL<DomainUser>(
7575
`SELECT * from users WHERE id = $1`,
76-
[targetUser.id],
76+
[targetUser.id]
7777
);
7878
expect(fetchedUser).toBeDefined();
7979
expect(fetchedUser?.rows[0]).toMatchObject({
@@ -96,7 +96,7 @@ describe("Repository Update", () => {
9696
const targetUser = users[1];
9797
const fetchedUsers = await executor.executeSQL<DomainUser>(
9898
`SELECT * FROM users WHERE id = $1`,
99-
[targetUser.id],
99+
[targetUser.id]
100100
);
101101
const originalUser = fetchedUsers.rows[0];
102102
expect(originalUser).toBeDefined();
@@ -108,7 +108,7 @@ describe("Repository Update", () => {
108108
},
109109
});
110110
expect(updatedUser).toBeDefined();
111-
expect(updatedUser.name).toBe("Partially Updated Name");
111+
expect(updatedUser?.name).toBe("Partially Updated Name");
112112
expect(updatedUser?.age).toBe(originalUser?.age); // Age should remain unchanged
113113
});
114114
});

0 commit comments

Comments
 (0)