-
Notifications
You must be signed in to change notification settings - Fork 1
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
a426048
commit e2668e0
Showing
4 changed files
with
92 additions
and
98 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
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import test from "tape"; | ||
import tiny from "tiny-json-http"; | ||
import sandbox from "@architect/sandbox"; | ||
|
||
const postReq = async (queryObj) => { | ||
const variables = queryObj.variables ? queryObj.variables : {}; | ||
return await tiny.post({ | ||
url: URL, | ||
data: { | ||
query: queryObj.query, | ||
variables: variables, | ||
}, | ||
}); | ||
}; | ||
const URL = "http://localhost:3333/"; | ||
|
||
test("setup", async (t) => { | ||
t.plan(1); | ||
await sandbox.start(); | ||
t.ok(true, `sandbox started on ${URL}`); | ||
}); | ||
|
||
test("test simple query", async (t) => { | ||
t.plan(1); | ||
const query = { | ||
name: "For basic server response/info", | ||
query: `query info { | ||
info | ||
}`, | ||
}; | ||
try { | ||
const res = await postReq(query); | ||
t.ok( | ||
res.body.hasOwnProperty("data"), | ||
`Test passed "${query.name}" query` | ||
); | ||
} catch (err) { | ||
t.fail(`Test failed "${query.name}" with ERROR :: ${err}`); | ||
} | ||
}); | ||
|
||
test("test fragment query", async (t) => { | ||
t.plan(1); | ||
const query = { | ||
name: "For fragment in GraphQL", | ||
query: `query userData ($userId: ID!) { | ||
user(userId: $userId) { ...userFragment } | ||
} | ||
fragment userFragment on User { | ||
name | ||
id | ||
username | ||
phone | ||
...websiteUserFragment | ||
posts { ...postsUserFragment } | ||
} | ||
fragment websiteUserFragment on User { website } | ||
fragment postsUserFragment on Post { | ||
postId | ||
userId | ||
title | ||
body | ||
comments { | ||
commentId | ||
postId | ||
name | ||
body | ||
} | ||
}`, | ||
variables: { | ||
userId: "10", | ||
}, | ||
}; | ||
try { | ||
const res = await postReq(query); | ||
t.ok( | ||
res.body.hasOwnProperty("data"), | ||
`Test passed "${query.name}" query` | ||
); | ||
} catch (err) { | ||
t.fail(`Test failed "${query.name}" with ERROR :: ${err}`); | ||
} | ||
}); | ||
|
||
test("teardown", async (t) => { | ||
t.plan(1); | ||
await sandbox.end(); | ||
t.ok(true, "sandbox ended"); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.