From 6a170f2f69af7c8cff787e0d69260a520ff50898 Mon Sep 17 00:00:00 2001 From: Paul Paterson Date: Tue, 15 Aug 2023 22:17:29 -0400 Subject: [PATCH 1/2] Get tests to pass when type checking is on. (#196) --- __tests__/integration/query.test.ts | 32 ++++++++--------------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/__tests__/integration/query.test.ts b/__tests__/integration/query.test.ts index 902e5f79..52234e09 100644 --- a/__tests__/integration/query.test.ts +++ b/__tests__/integration/query.test.ts @@ -186,7 +186,7 @@ describe("query", () => { if (e instanceof QueryCheckError) { expect(e.httpStatus).toBe(400); expect(e.message).toBeDefined(); - expect(e.code).toBeDefined(); + expect(e.code).toBe("invalid_query"); expect(e.queryInfo?.summary).toBeDefined(); } } @@ -195,7 +195,7 @@ describe("query", () => { it("throws a QueryRuntimeError if the query hits a runtime error", async () => { expect.assertions(3); try { - await client.query(fql`"taco".length + "taco"`); + await client.query(fql`2 + "2"`, { typecheck: false }); } catch (e) { if (e instanceof QueryRuntimeError) { expect(e.httpStatus).toBe(400); @@ -458,7 +458,6 @@ describe("query", () => { describe("query can encode / decode QueryValue correctly", () => { it("treats undefined as unprovided when in object", async () => { - const client = getClient(); const collectionName = "UndefinedTest"; await client.query(fql` if (Collection.byName(${collectionName}) == null) { @@ -474,36 +473,23 @@ describe("query can encode / decode QueryValue correctly", () => { i_dont_exist: undefined, }, }; - const docCreated = await client.query(fql` - ${new Module(collectionName)}.create(${toughInput})`); - client.close(); + // Do not use a dynamic Collection name by using `${new Module(collectionName)}`. See ENG-5003 + const docCreated = await client.query( + fql`UndefinedTest.create(${toughInput})` + ); expect(docCreated.data.should_exist).toBeUndefined(); expect(docCreated.data.nested_object.i_dont_exist).toBeUndefined(); expect(docCreated.data.foo).toBe("bar"); expect(docCreated.data.nested_object.i_exist).toBe(true); }); - it("treats undefined as unprovided passed directly as value", async () => { + it("undefined arguments throw a TypeError", async () => { expect.assertions(2); - const client = getClient(); - const collectionName = "UndefinedTest"; - await client.query(fql` - if (Collection.byName(${collectionName}) == null) { - Collection.create({ name: ${collectionName}}) - }`); // whack in undefined // @ts-expect-error Type 'undefined' is not assignable to type 'QueryValue' let undefinedValue: QueryValue = undefined; try { - await client.query(fql` - ${new Module(collectionName)}.create({ - foo: "bar", - shouldnt_exist: ${undefinedValue}, - nested_object: { - i_exist: true, - i_dont_exist: ${undefinedValue} - } - })`); + await client.query(fql`{ foo: ${undefinedValue} }`); } catch (e) { if (e instanceof TypeError) { expect(e.name).toBe("TypeError"); @@ -511,8 +497,6 @@ describe("query can encode / decode QueryValue correctly", () => { "Passing undefined as a QueryValue is not supported" ); } - } finally { - client.close(); } }); }); From e076988c73ead37f3d83fe440864eb620319e7a2 Mon Sep 17 00:00:00 2001 From: Darren Cunningham Date: Sun, 20 Aug 2023 21:43:46 -0400 Subject: [PATCH 2/2] Updated doc comment (#193) --- src/client-configuration.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/client-configuration.ts b/src/client-configuration.ts index af4e6b00..d9e473ef 100644 --- a/src/client-configuration.ts +++ b/src/client-configuration.ts @@ -75,9 +75,7 @@ export interface ClientConfiguration { /** * The timeout of each query, in milliseconds. This controls the maximum amount of - * time Fauna will execute your query before marking it failed. - * Default is undefined which let's Fauna determine the query timeout to apply. This - * is recommended for most queries. The default is 5000 ms. + * time Fauna will execute your query before marking it failed. The default is 5000 ms. */ query_timeout_ms?: number;