Skip to content

Commit

Permalink
updated testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
dhyeythumar committed Jan 17, 2022
1 parent a426048 commit e2668e0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 98 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"scripts": {
"start": "npx sandbox",
"test": "tape tests/*.test.js | tap-spec"
"test": "tape test/*-test.js | tap-spec"
},
"repository": {
"type": "git",
Expand Down
91 changes: 91 additions & 0 deletions test/any-catchall-test.js
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
email
phone
...websiteUserFragment
posts { ...postsUserFragment }
}
fragment websiteUserFragment on User { website }
fragment postsUserFragment on Post {
postId
userId
title
body
comments {
commentId
postId
name
email
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");
});
43 changes: 0 additions & 43 deletions tests/Queries.js

This file was deleted.

54 changes: 0 additions & 54 deletions tests/graphqlServer.test.js

This file was deleted.

0 comments on commit e2668e0

Please sign in to comment.