-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updatedAt field not updating on mutations
- Loading branch information
Showing
12 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,47 @@ describe("write hooks", () => { | |
}) | ||
).toHaveAuthorizationError(); | ||
}); | ||
|
||
|
||
test("update action - updatedAt set", async () => { | ||
const identity = await models.identity.create({ | ||
email: "[email protected]", | ||
}); | ||
const name = "Alice"; | ||
|
||
const person = await models.person.create({ | ||
sex: Sex.Female, | ||
title: name, | ||
}); | ||
|
||
expect(person.updatedAt).not.toBeNull(); | ||
expect(person.updatedAt).toEqual(person.createdAt); | ||
|
||
await delay(100); | ||
|
||
const record = await actions | ||
.withIdentity(identity) | ||
.updatePersonWithBeforeWrite({ | ||
where: { id: person.id }, | ||
values: { | ||
title: "Alice", | ||
sex: Sex.Female, | ||
}, | ||
}); | ||
console.log(person); | ||
console.log(record); | ||
|
||
const person2 = await models.person.findOne({id: person.id}); | ||
console.log(person2); | ||
|
||
|
||
expect(record.updatedAt.valueOf()).toBeGreaterThanOrEqual(person.createdAt.valueOf() + 100); | ||
expect(record.updatedAt.valueOf()).toBeLessThan(person.createdAt.valueOf() + 1000); | ||
}); | ||
|
||
function delay(ms: number) { | ||
return new Promise( resolve => setTimeout(resolve, ms) ); | ||
} | ||
}); | ||
|
||
describe("query hooks", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE OR REPLACE FUNCTION set_updated_at() RETURNS TRIGGER AS $$ | ||
BEGIN | ||
NEW.updated_at = NOW(); | ||
RETURN NEW; | ||
END | ||
$$ LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters