Writing Tests
In order to test new functionality, we'll update the existing .__tests__/e2e.spec.ts
query and mutation files to include the new queries we have previously added:
# Import query/w3 files and /testUtils files
import * as QuerySchema from "../../query/w3"
import { getPlugins } from "../testUtils"
# Set jest timeout for e2e test
jest.setTimeout(150000)
# Test the queries
describe("Query", () => {
let client: Web3ApiClient;
let ensUri: string;
beforeAll(async () => {
const { ensAddress, ethereum, ipfs } = await initTestEnvironment();
const apiPath = path.join(__dirname, "/../../../");
const api = await buildAndDeployApi(apiPath, ipfs, ensAddress);
ensUri = `ens/testnet/${api.ensDomain}`;
client = new Web3ApiClient({
plugins: getPlugins(ipfs, ensAddress, ethereum),
})
})
afterAll(async () => {
await stopTestEnvironment()
})
describe("resolveDomain", () => {
it("should resolve a valid domain name", async () => {
const response = await client.query<{ resolveDomain: QuerySchema.DomainInfo | null }>({
uri: ensUri,
query: `
query {
resolveDomain(
network: mainnet,
domain: $domain
)
}
`,
variables: {
domain: "alice.tez"
}
})
expect(response.errors).toBeUndefined()
expect(response.data).toBeDefined()
expect(response.data?.resolveDomain).toBeDefined()
expect(response.data?.resolveDomain?.Name).toBeDefined()
expect(response.data?.resolveDomain?.Address).toBeDefined()
expect(response.data?.resolveDomain?.Data).toBeDefined()
expect(response.data?.resolveDomain?.Expiry).toBeDefined()
})
it("should return null for an invalid domain name", async () => {
const response = await client.query<{ resolveDomain: QuerySchema.DomainInfo | null }>({
uri: ensUri,
query: `
query {
resolveDomain(
network: mainnet,
domain: $domain
)
}
`,
variables: {
domain: `chalak-${Math.random() * 1000}.tez`
}
})
expect(response.errors).toBeUndefined()
expect(response.data).toBeDefined()
expect(response.data?.resolveDomain).toBeNull()
})
})
})
Last updated