Skip to content

Commit

Permalink
Get tests to pass when type checking is on. (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptpaterson authored Aug 16, 2023
1 parent 00e2ce6 commit 6a170f2
Showing 1 changed file with 8 additions and 24 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();
}
});
});

0 comments on commit 6a170f2

Please sign in to comment.