Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/beta' into update-links
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodewig committed May 7, 2024
2 parents cf036f8 + 90499c5 commit 86d5462
Show file tree
Hide file tree
Showing 14 changed files with 764 additions and 515 deletions.
546 changes: 305 additions & 241 deletions README.md

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions __tests__/integration/doc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,23 @@ describe("querying for doc types", () => {
expect(result.data.module).toBeInstanceOf(Module);
expect(result.data.document).toBeInstanceOf(Document);
expect(result.data.document.documentReference).toBeInstanceOf(
DocumentReference
DocumentReference,
);
expect(result.data.document.namedDocumentReference).toBeInstanceOf(
NamedDocumentReference
NamedDocumentReference,
);
expect(result.data.namedDocument).toBeInstanceOf(NamedDocument);
});

it("can set and read ttl", async () => {
const queryBuilder = fql`${testDoc}`;
const result = await client.query<Document>(queryBuilder);

expect(result.data.ttl).toBeUndefined();

const queryBuilderUpdate = fql`${testDoc}.update({ ttl: Time.now().add(1, "day") })`;
const resultUpdate = await client.query<Document>(queryBuilderUpdate);

expect(resultUpdate.data.ttl).toBeInstanceOf(TimeStub);
});
});
77 changes: 38 additions & 39 deletions __tests__/integration/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ describe("query", () => {
expect(req.headers[expectedHeader.key]).toBe(expectedHeader.value);
});
expect(req.headers["x-driver-env"]).toEqual(
expect.stringContaining("driver=")
expect.stringContaining("driver="),
);
expect(req.headers["x-driver-env"]).toEqual(
expect.stringContaining("os=")
expect.stringContaining("os="),
);
expect(req.headers["x-driver-env"]).toEqual(
expect.stringContaining("runtime=")
expect.stringContaining("runtime="),
);
return dummyResponse;
},
Expand All @@ -150,33 +150,31 @@ describe("query", () => {
const headers = { [fieldName]: fieldValue };
await myClient.query<number>(fql`"taco".length`, headers);
myClient.close();
}
},
);

it(
"respects typechecked: undefined", async () => {
const httpClient: HTTPClient = {
async request(req) {
const contains = new Set(Object.keys(req.headers)).has("x-typecheck");
expect(contains).toBe(false);
return dummyResponse;
},
close() {},
};

let clientConfiguration: Partial<ClientConfiguration> = {
typecheck: true,
};
let myClient = getClient(clientConfiguration, httpClient);
await myClient.query<number>(fql`"taco".length`, { typecheck: undefined });
myClient.close();
it("respects typechecked: undefined", async () => {
const httpClient: HTTPClient = {
async request(req) {
const contains = new Set(Object.keys(req.headers)).has("x-typecheck");
expect(contains).toBe(false);
return dummyResponse;
},
close() {},
};

clientConfiguration = { typecheck: undefined };
myClient = getClient(clientConfiguration, httpClient);
await myClient.query<number>(fql`"taco".length`);
myClient.close();
}
);
let clientConfiguration: Partial<ClientConfiguration> = {
typecheck: true,
};
let myClient = getClient(clientConfiguration, httpClient);
await myClient.query<number>(fql`"taco".length`, { typecheck: undefined });
myClient.close();

clientConfiguration = { typecheck: undefined };
myClient = getClient(clientConfiguration, httpClient);
await myClient.query<number>(fql`"taco".length`);
myClient.close();
});

it("can send arguments directly", async () => {
const foo = {
Expand Down Expand Up @@ -234,10 +232,10 @@ describe("query", () => {
expect.assertions(6);
try {
await client.query(
fql`Function.create({"name": "my_double", "body": "x => x * 2"})`
fql`Function.create({"name": "my_double", "body": "x => x * 2"})`,
);
await client.query(
fql`Function.create({"name": "my_double", "body": "x => x * 2"})`
fql`Function.create({"name": "my_double", "body": "x => x * 2"})`,
);
} catch (e) {
if (e instanceof ServiceError) {
Expand Down Expand Up @@ -266,7 +264,7 @@ describe("query", () => {
data: "{}" as unknown as QueryRequest,
};
return getDefaultHTTPClient(getDefaultHTTPClientOptions()).request(
bad_req
bad_req,
);
},
close() {},
Expand Down Expand Up @@ -307,7 +305,7 @@ describe("query", () => {
} catch (e) {
if (e instanceof QueryTimeoutError) {
expect(e.message).toEqual(
expect.stringContaining("aggressive deadline")
expect.stringContaining("aggressive deadline"),
);
expect(e.httpStatus).toBe(440);
expect(e.code).toBe("time_out");
Expand Down Expand Up @@ -366,7 +364,7 @@ describe("query", () => {
});

it("throws a NetworkError on client timeout", async () => {
expect.assertions(2);
expect.assertions(3);

const httpClient = getDefaultHTTPClient(getDefaultHTTPClientOptions());
const badHTTPClient = {
Expand All @@ -384,6 +382,7 @@ describe("query", () => {
try {
await badClient.query(fql``);
} catch (e: any) {
expect(e).toBeInstanceOf(NetworkError);
if (e instanceof NetworkError) {
expect(e.message).toBe("The network connection encountered a problem.");
expect(e.cause).toBeDefined();
Expand All @@ -403,15 +402,15 @@ describe("query", () => {
{
query_timeout_ms: 60,
},
httpClient
httpClient,
);
try {
await badClient.query(fql`foo`);
} catch (e: any) {
if (e instanceof ClientError) {
expect(e.cause).toBeDefined();
expect(e.message).toBe(
"A client level error occurred. Fauna was not called."
"A client level error occurred. Fauna was not called.",
);
}
} finally {
Expand Down Expand Up @@ -440,13 +439,13 @@ describe("query", () => {

it("session is closed regardless of number of clients", async () => {
const httpClient1 = NodeHTTP2Client.getClient(
getDefaultHTTPClientOptions()
getDefaultHTTPClientOptions(),
);
const httpClient2 = NodeHTTP2Client.getClient(
getDefaultHTTPClientOptions()
getDefaultHTTPClientOptions(),
);
const httpClient3 = NodeHTTP2Client.getClient(
getDefaultHTTPClientOptions()
getDefaultHTTPClientOptions(),
);
const client1 = getClient({}, httpClient1);
const client2 = getClient({}, httpClient2);
Expand Down Expand Up @@ -500,7 +499,7 @@ describe("query can encode / decode QueryValue correctly", () => {
};
// 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})`
fql`UndefinedTest.create(${toughInput})`,
);
expect(docCreated.data.should_exist).toBeUndefined();
expect(docCreated.data.nested_object.i_dont_exist).toBeUndefined();
Expand All @@ -519,7 +518,7 @@ describe("query can encode / decode QueryValue correctly", () => {
if (e instanceof TypeError) {
expect(e.name).toBe("TypeError");
expect(e.message).toBe(
"Passing undefined as a QueryValue is not supported"
"Passing undefined as a QueryValue is not supported",
);
}
}
Expand Down
Loading

0 comments on commit 86d5462

Please sign in to comment.