Skip to content

Commit

Permalink
Add test helpers (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
macmv authored Jul 19, 2023
1 parent fcc2d70 commit 02277d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
23 changes: 22 additions & 1 deletion __tests__/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Client, ClientConfiguration, endpoints, HTTPClient } from "../src";
import {
Client,
ClientConfiguration,
endpoints,
fql,
HTTPClient,
} from "../src";
import { HTTPClientOptions } from "../src/http-client/http-client";

export const getClient = (
Expand Down Expand Up @@ -36,3 +42,18 @@ export const getDefaultHTTPClientOptions = (): HTTPClientOptions => {
fetch_keepalive: false,
};
};

export const newDB = async (name: string): Promise<Client> => {
const parentClient = getClient();

const secretQ = await parentClient.query<string>(fql`
if (Database.byName(${name}).exists()) {
Key.where(.database == ${name}).forEach(.delete())
Database.byName(${name})!.delete()
}
Database.create({ name: ${name} })
Key.create({ role: "admin", database: ${name} }).secret
`);

return getClient({ secret: secretQ.data });
};
18 changes: 10 additions & 8 deletions __tests__/integration/schema-version.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { fql } from "../../src";
import { getClient } from "../client";
import { Client, fql } from "../../src";
import { newDB } from "../client";

describe("schema version is returned by the client", () => {
const client = getClient();
let client: Client;

// make a fresh db each run
beforeAll(async () => {
client = await newDB("SchemaTest");
});

it("returns the schema version", async () => {
const resTs = await client.query(fql`
if (Collection.byName("TestColl") == null) {
Collection.create({ name: "TestColl" })
} else {
TestColl.definition.update({})
}
Collection.create({ name: "TestColl" })
`);

const expectedSchemaVersion = resTs.txn_ts;
Expand Down

0 comments on commit 02277d8

Please sign in to comment.