From b58699ee6f445d35c4930bf20626971d0f85f9c7 Mon Sep 17 00:00:00 2001 From: Dave New Date: Mon, 30 Oct 2023 17:28:51 +0200 Subject: [PATCH] chore: prettier and clean up --- .../with_custom_function_hooks/main.test.ts | 33 +++++++++---------- migrations/testdata/default_value_initial.txt | 2 +- packages/testing-runtime/src/Executor.mjs | 12 +++---- runtime/actions/query.go | 4 --- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/integration/testdata/with_custom_function_hooks/main.test.ts b/integration/testdata/with_custom_function_hooks/main.test.ts index 33782ba6f..1e23f4ae1 100644 --- a/integration/testdata/with_custom_function_hooks/main.test.ts +++ b/integration/testdata/with_custom_function_hooks/main.test.ts @@ -30,14 +30,14 @@ describe("write hooks", () => { actions.withIdentity(identity).createPersonWithAfterWrite({ title: "Bob", sex: Sex.Male, - }) + }), ).toHaveAuthorizationError(); await expect( actions.withIdentity(identity).createPersonWithBeforeWrite({ title: "Alice", sex: Sex.Female, - }) + }), ).not.toHaveAuthorizationError(); }); @@ -83,12 +83,11 @@ describe("write hooks", () => { title: "Adam", sex: Sex.Male, }, - }) + }), ).toHaveAuthorizationError(); }); - - test("update action - updatedAt set", async () => { + test("update.beforeWrite hook - updatedAt set", async () => { const identity = await models.identity.create({ email: "adam@keel.xyz", }); @@ -104,7 +103,7 @@ describe("write hooks", () => { await delay(100); - const record = await actions + const record = await actions .withIdentity(identity) .updatePersonWithBeforeWrite({ where: { id: person.id }, @@ -113,19 +112,17 @@ describe("write hooks", () => { 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); + 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) ); + return new Promise((resolve) => setTimeout(resolve, ms)); } }); @@ -140,7 +137,7 @@ describe("query hooks", () => { }); await expect( - actions.withIdentity(identity).deletePersonBeforeQuery({ id: person.id }) + actions.withIdentity(identity).deletePersonBeforeQuery({ id: person.id }), ).toHaveError({ message: "record not found", }); @@ -188,7 +185,7 @@ describe("query hooks", () => { await expect( actions.withIdentity(identity).getPersonBeforeQuery({ id: person.id, - }) + }), ).toHaveError({ message: "no result", }); @@ -274,7 +271,7 @@ describe("query hooks", () => { sex: Sex.Male, title: person.title, }, - }) + }), ).rejects.toThrowError("record not found"); }); diff --git a/migrations/testdata/default_value_initial.txt b/migrations/testdata/default_value_initial.txt index 782c28cbb..fd71ffac2 100644 --- a/migrations/testdata/default_value_initial.txt +++ b/migrations/testdata/default_value_initial.txt @@ -21,7 +21,7 @@ model Person { === CREATE TABLE "identity" ( -"email" TEXT,pauthen +"email" TEXT, "email_verified" BOOL NOT NULL DEFAULT false, "password" TEXT, "external_id" TEXT, diff --git a/packages/testing-runtime/src/Executor.mjs b/packages/testing-runtime/src/Executor.mjs index 2f2895255..7eed62125 100644 --- a/packages/testing-runtime/src/Executor.mjs +++ b/packages/testing-runtime/src/Executor.mjs @@ -75,7 +75,7 @@ export class Executor { method: "POST", body: JSON.stringify(params), headers, - }).then(async (r) => { + }).then((r) => { if (r.status !== 200) { // For non-200 first read the response as text return r.text().then((t) => { @@ -101,11 +101,11 @@ export class Executor { }); } - return r.text().then((t) => { - if (this._parseJsonResult) { + if (this._parseJsonResult) { + return r.text().then((t) => { return JSON.parse(t, reviver); - } - }); + }); + } }); } } @@ -117,4 +117,4 @@ function reviver(key, value) { return new Date(value); } return value; -} \ No newline at end of file +} diff --git a/runtime/actions/query.go b/runtime/actions/query.go index a36b3ecc5..1ad701e7a 100644 --- a/runtime/actions/query.go +++ b/runtime/actions/query.go @@ -6,7 +6,6 @@ import ( "fmt" "sort" "strings" - "time" "github.com/samber/lo" "github.com/teamkeel/keel/casing" @@ -812,9 +811,6 @@ func orderGraphNodes(graph *Row) []*Row { // Generates an executable UPDATE statement with the list of arguments. func (query *QueryBuilder) UpdateStatement() *Statement { - // Implicitly update the updatedAt column for any update to the model - query.AddWriteValue(Field(parser.ImplicitFieldNameUpdatedAt), Value(time.Now().UTC())) - queryFilters := query.filters joins := ""