Skip to content

Commit

Permalink
test: adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
4lejandrito committed Oct 13, 2023
1 parent 24a4553 commit 28da31e
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 10 deletions.
121 changes: 113 additions & 8 deletions test/__snapshots__/fetchbook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,122 @@ exports[`fetchbook run --all 2`] = `
✔ Charizard 200
✔ Get a missing post 404
✔ Get a post 200
✔ Get all posts 200
✘ Get all posts 200"
`;

exports[`fetchbook run --all 3`] = `
"error: expect(received).toMatchObject(expected)
- Expected - 1
+ Received + 1
Object {
"headers": Object {
"content-type": "application/json; charset=utf-8",
},
- "status": 201,
+ "status": 200,
}"
`;

exports[`fetchbook run test/pass --all 1`] = `0`;

exports[`fetchbook run test/pass --all 2`] = `
"✔ Add a post 201
✔ Add a post 201
✔ Add a post 201
✔ Add a post 201
✔ Add and get several posts 200
✔ Get a missing post 404
✔ Get a post 200
✔ Get all posts 200"
`;

exports[`fetchbook run test/pass --all 3`] = `""`;

exports[`fetchbook run test/fail --all 1`] = `0`;

exports[`fetchbook run test/fail --all 2`] = `"✘ Get all posts 200"`;

exports[`fetchbook run test/fail --all 3`] = `
"error: expect(received).toMatchObject(expected)
- Expected - 1
+ Received + 1
Object {
"headers": Object {
"content-type": "application/json; charset=utf-8",
},
- "status": 201,
+ "status": 200,
}"
`;

exports[`fetchbook run test --all 1`] = `0`;

exports[`fetchbook run test --all 2`] = `
"✔ Add a post 201
✔ Add a post 201
✔ Add a post 201
✔ Add a post 201
✔ Add and get several posts 200
✔ Get a missing post 404
✔ Get a post 200
✘ Get all posts 200"
`;

exports[`fetchbook run test --all 3`] = `
"error: expect(received).toMatchObject(expected)
- Expected - 1
+ Received + 1
Object {
"headers": Object {
"content-type": "application/json; charset=utf-8",
},
- "status": 201,
+ "status": 200,
}"
`;

exports[`fetchbook run examples --all 1`] = `0`;

exports[`fetchbook run examples --all 2`] = `
"✔ A Link to the Past 200
✔ Blastoise 200
✔ Charizard 200
✔ Ocarina of Time 200
✔ Venusaur 200"
`;

exports[`fetchbook run --all 3`] = `""`;
exports[`fetchbook run examples --all 3`] = `""`;

exports[`fetchbook run test/pass/add-post.fetch.ts 1`] = `0`;

exports[`fetchbook run test/pass/add-post.fetch.ts 2`] = `"✔ Add a post 201"`;

exports[`fetchbook run test/posts/add-post.fetch.ts 1`] = `0`;
exports[`fetchbook run test/pass/add-post.fetch.ts 3`] = `""`;

exports[`fetchbook run test/posts/add-post.fetch.ts 2`] = `"✔ Add a post 201"`;
exports[`fetchbook run test/fail/get-posts.fetch.ts 1`] = `0`;

exports[`fetchbook run test/posts/add-post.fetch.ts 3`] = `""`;
exports[`fetchbook run test/fail/get-posts.fetch.ts 2`] = `"✘ Get all posts 200"`;

exports[`fetchbook run test/fail/get-posts.fetch.ts 3`] = `
"error: expect(received).toMatchObject(expected)
- Expected - 1
+ Received + 1
Object {
"headers": Object {
"content-type": "application/json; charset=utf-8",
},
- "status": 201,
+ "status": 200,
}"
`;

exports[`fetchbook export --all 1`] = `0`;

Expand All @@ -86,14 +190,15 @@ curl 'https://pokeapi.co/api/v2/pokemon/charizard' -X GET
curl 'http://localhost:3000/posts/0' -X GET
curl 'http://localhost:3000/posts/1' -X GET -H "some-header: value"
curl 'http://localhost:3000/posts' -X GET -H "some-header: value"
curl 'http://localhost:3000/posts' -X GET -H "some-header: value"
curl 'https://zelda.fanapis.com/api/games/5f6ce9d805615a85623ec2ba' -X GET
curl 'https://pokeapi.co/api/v2/pokemon/venusaur' -X GET"
`;

exports[`fetchbook export --all 3`] = `""`;

exports[`fetchbook export test/posts/add-post.fetch.ts 1`] = `0`;
exports[`fetchbook export test/pass/add-post.fetch.ts 1`] = `0`;

exports[`fetchbook export test/posts/add-post.fetch.ts 2`] = `"curl 'http://localhost:3000/posts' -X POST -H "content-type: application/json" --data-binary '{"it":"works!"}'"`;
exports[`fetchbook export test/pass/add-post.fetch.ts 2`] = `"curl 'http://localhost:3000/posts' -X POST -H "content-type: application/json" --data-binary '{"it":"works!"}'"`;

exports[`fetchbook export test/posts/add-post.fetch.ts 3`] = `""`;
exports[`fetchbook export test/pass/add-post.fetch.ts 3`] = `""`;
18 changes: 18 additions & 0 deletions test/fail/get-posts.fetch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FetchStory } from "fetchbook";

export default {
name: "Get all posts",
url: "http://localhost:3000/posts",
init: {
method: "GET",
headers: {
"Some-Header": "value",
},
},
expect: {
status: 201,
headers: {
"content-type": "application/json; charset=utf-8",
},
},
} satisfies FetchStory;
9 changes: 7 additions & 2 deletions test/fetchbook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ $test`fetchbook`;
$test`fetchbook --help`;
$test`fetchbook --version`;
$test`fetchbook run --all`;
$test`fetchbook run test/posts/add-post.fetch.ts`;
$test`fetchbook run test/pass --all`;
$test`fetchbook run test/fail --all`;
$test`fetchbook run test --all`;
$test`fetchbook run examples --all`;
$test`fetchbook run test/pass/add-post.fetch.ts`;
$test`fetchbook run test/fail/get-posts.fetch.ts`;
$test`fetchbook export --all`;
$test`fetchbook export test/posts/add-post.fetch.ts`;
$test`fetchbook export test/pass/add-post.fetch.ts`;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 28da31e

Please sign in to comment.