Skip to content

Commit

Permalink
chore: extract queryGql function
Browse files Browse the repository at this point in the history
  • Loading branch information
bob2402 committed Apr 6, 2024
1 parent 47cfe67 commit 1f7c7c9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,8 @@ Deno.test("NIP-11: Relay Information Document", async (t) => {
});

await t.step("graphql", async () => {
const { hostname, port } = new URL(relay.url);
const res = await fetch(`http://${hostname}:${port}/api`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"password": "123",
},
body: JSON.stringify({ query: await Deno.readTextFile("./queries/getRelayInfomation.gql") }),
});
const json = await res.json();
const query = await Deno.readTextFile("./queries/getRelayInfomation.gql")
const json = await queryGql(relay, query);
assertEquals(json.data.relayInformation.name, "Nostr Relay2");
});

Expand All @@ -189,3 +181,16 @@ async function randomEvent(ctx: InMemoryAccountContext, kind?: NostrKind, conten
});
return event;
}

async function queryGql(relay: Relay, query: string) {
const { hostname, port } = new URL(relay.url);
const res = await fetch(`http://${hostname}:${port}/api`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"password": "123",
},
body: JSON.stringify({ query }),
});
return await res.json();
}

0 comments on commit 1f7c7c9

Please sign in to comment.