File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments