Skip to content

Commit

Permalink
Merge branch 'main' into bt-4101-ga-launch
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwpedro authored Aug 21, 2023
2 parents f562f2d + e076988 commit 578a42e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
32 changes: 8 additions & 24 deletions __tests__/integration/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -474,45 +473,30 @@ describe("query can encode / decode QueryValue correctly", () => {
i_dont_exist: undefined,
},
};
const docCreated = await client.query<any>(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<any>(
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");
expect(e.message).toBe(
"Passing undefined as a QueryValue is not supported"
);
}
} finally {
client.close();
}
});
});
4 changes: 1 addition & 3 deletions src/client-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 578a42e

Please sign in to comment.