Skip to content

Commit bbf6058

Browse files
fix tests http request
1 parent 85c9d58 commit bbf6058

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/PokeApi.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@ export class PokeApi extends Context.Tag("PokeApi")<
4343
static readonly Test = Layer.succeed(
4444
this,
4545
PokeApi.of({
46-
getPokemon: Effect.succeed({
47-
id: 1,
48-
height: 10,
49-
weight: 10,
50-
name: "my-name",
51-
order: 1,
46+
getPokemon: Effect.gen(function* () {
47+
const response = yield* Effect.tryPromise({
48+
try: () => fetch(`http://localhost:3000/api/v2/pokemon/garchomp/`),
49+
catch: () => new FetchError(),
50+
});
51+
52+
if (!response.ok) {
53+
return yield* new FetchError();
54+
}
55+
56+
const json = yield* Effect.tryPromise({
57+
try: () => response.json(),
58+
catch: () => new JsonError(),
59+
});
60+
61+
return yield* Schema.decodeUnknown(Pokemon)(json);
5262
}),
5363
})
5464
);

src/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ it("returns a valid pokemon", async () => {
1717
height: 10,
1818
weight: 10,
1919
order: 1,
20-
name: "my-name",
20+
name: "myname",
2121
});
2222
});

0 commit comments

Comments
 (0)