-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
003280d
commit 2a8b6b0
Showing
1 changed file
with
39 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,52 @@ | ||
import {describe, test, expect} from "vitest" | ||
import {describe, expect, test} from "vitest" | ||
import {readFile} from "fs/promises" | ||
import {mf} from "./mf" | ||
|
||
describe("fetch", () => { | ||
test("loadfiles", async () => { | ||
let placeholder = (await readFile("../examples/jsonplaceholder.graphql")).toString() | ||
let placeholder_batch = (await readFile("../examples/jsonplaceholder_batch.graphql")).toString() | ||
let grpc = (await readFile("../examples/grpc.graphql")).toString() | ||
let news_proto = (await readFile("../tailcall-fixtures/fixtures/protobuf/news.proto")).toString() | ||
test("loadfiles", async () => { | ||
let placeholder = (await readFile("../examples/jsonplaceholder.graphql")).toString() | ||
let placeholder_batch = (await readFile("../examples/jsonplaceholder_batch.graphql")).toString() | ||
let grpc = (await readFile("../examples/grpc.graphql")).toString() | ||
let news_proto = (await readFile("../tailcall-fixtures/fixtures/protobuf/news.proto")).toString() | ||
|
||
let bucket = await mf.getR2Bucket("MY_R2") | ||
await bucket.put("examples/grpc.graphql", grpc) | ||
await bucket.put("examples/../tailcall-fixtures/fixtures/protobuf/news.proto", news_proto) | ||
await bucket.put("tailcall-fixtures/fixtures/protobuf/news.proto", grpc) | ||
await bucket.put("examples/jsonplaceholder.graphql", placeholder) | ||
await bucket.put("examples/jsonplaceholder_batch.graphql", placeholder_batch) | ||
}) | ||
|
||
test("ide", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/", { | ||
method: "GET", | ||
let bucket = await mf.getR2Bucket("MY_R2") | ||
await bucket.put("examples/grpc.graphql", grpc) | ||
await bucket.put("examples/../tailcall-fixtures/fixtures/protobuf/news.proto", news_proto) | ||
await bucket.put("tailcall-fixtures/fixtures/protobuf/news.proto", grpc) | ||
await bucket.put("examples/jsonplaceholder.graphql", placeholder) | ||
await bucket.put("examples/jsonplaceholder_batch.graphql", placeholder_batch) | ||
}) | ||
let body = await resp.text() | ||
expect(body.includes("<title>Tailcall - GraphQL IDE</title>")).toBe(true) | ||
expect(resp.status).toBe(200) | ||
}) | ||
|
||
test("sample_resp", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/jsonplaceholder.graphql", { | ||
method: "POST", | ||
body: '{"query":"{user(id: 1) {id}}"}', | ||
test("sample_resp", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/jsonplaceholder.graphql", { | ||
method: "POST", | ||
body: '{"query":"{user(id: 1) {id}}"}', | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {user: {id: 1}}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {user: {id: 1}}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
|
||
test("test_batching", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/jsonplaceholder_batch.graphql", { | ||
method: "POST", | ||
body: '{"query":"{ posts { id } }"}', | ||
test("test_batching", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/jsonplaceholder_batch.graphql", { | ||
method: "POST", | ||
body: '{"query":"{ posts { id } }"}', | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {posts: [{id: 1}]}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {posts: [{id: 1}]}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
|
||
test("test_grpc", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/grpc.graphql", { | ||
method: "POST", | ||
body: '{"query":"{ news { news { id } } }"}', | ||
test("test_grpc", async () => { | ||
let resp = await mf.dispatchFetch("https://fake.host/graphql?config=examples/grpc.graphql", { | ||
method: "POST", | ||
body: '{"query":"{ news { news { id } } }"}', | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {news: {news: [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]}}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
let body = await resp.json() | ||
let expected = {data: {news: {news: [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}]}}} | ||
expect(body).toEqual(expected) | ||
expect(resp.status).toBe(200) | ||
}) | ||
}) |