@@ -77,72 +77,60 @@ describe("RemoteStore — error handling", () => {
7777 } ) ;
7878} ) ;
7979
80- describe ( "RemoteStore — remaining store methods" , ( ) => {
81- function makeTrackedStore ( impl ) {
82- const fetchFn = vi . fn ( impl ) ;
83- vi . stubGlobal ( "fetch" , fetchFn ) ;
84- return { store : new RemoteStore ( "http://localhost:3000" , "test-key" ) , fetchFn } ;
85- }
86-
87- it ( "deleteItem sends DELETE" , async ( ) => {
88- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { } ) ) ;
89- await store . deleteItem ( 1 ) ;
90- expect ( fetchFn . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( "DELETE" ) ;
80+ describe ( "RemoteStore — all store methods return API data" , ( ) => {
81+ it ( "deleteItem resolves without error" , async ( ) => {
82+ const store = makeStore ( ( ) => mockResponse ( 200 , { deleted : 1 } ) ) ;
83+ await expect ( store . deleteItem ( 1 ) ) . resolves . not . toThrow ( ) ;
9184 } ) ;
9285
93- it ( "searchItems builds correct query string" , async ( ) => {
94- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , [ ] ) ) ;
95- await store . searchItems ( "login bug" , "open" ) ;
96- const url = fetchFn . mock . calls [ 0 ] [ 0 ] ;
97- expect ( url ) . toContain ( "q=login%20bug" ) ;
98- expect ( url ) . toContain ( "status=open" ) ;
86+ it ( "searchItems returns matching results" , async ( ) => {
87+ const store = makeStore ( ( ) => mockResponse ( 200 , [ { id : 1 , title : "login bug" } ] ) ) ;
88+ const results = await store . searchItems ( "login bug" , "open" ) ;
89+ expect ( results ) . toHaveLength ( 1 ) ;
90+ expect ( results [ 0 ] . title ) . toBe ( "login bug" ) ;
9991 } ) ;
10092
101- it ( "addChecklist sends POST to checklist endpoint" , async ( ) => {
102- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { id : 1 , label : "Step" } ) ) ;
103- const result = await store . addChecklist ( 5 , { version : 1 , label : "Step" } ) ;
104- expect ( result . label ) . toBe ( "Step" ) ;
105- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "/api/items/5/checklist" ) ;
93+ it ( "addChecklist returns the created checklist item" , async ( ) => {
94+ const store = makeStore ( ( ) => mockResponse ( 200 , { id : 7 , label : "Step 1" , checked : false } ) ) ;
95+ const cl = await store . addChecklist ( 5 , { version : 1 , label : "Step 1" } ) ;
96+ expect ( cl . id ) . toBe ( 7 ) ;
97+ expect ( cl . label ) . toBe ( "Step 1" ) ;
98+ expect ( cl . checked ) . toBe ( false ) ;
10699 } ) ;
107100
108- it ( "updateChecklist sends PATCH" , async ( ) => {
109- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { id : 1 , checked : true } ) ) ;
110- const result = await store . updateChecklist ( 5 , { version : 2 , id : 1 , checked : true } ) ;
111- expect ( fetchFn . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( "PATCH" ) ;
112- expect ( result . checked ) . toBe ( true ) ;
101+ it ( "updateChecklist returns the updated checklist item" , async ( ) => {
102+ const store = makeStore ( ( ) => mockResponse ( 200 , { id : 7 , label : "Step 1" , checked : true } ) ) ;
103+ const cl = await store . updateChecklist ( 5 , { version : 2 , id : 7 , checked : true } ) ;
104+ expect ( cl . checked ) . toBe ( true ) ;
113105 } ) ;
114106
115- it ( "deleteChecklist sends DELETE to checklist item endpoint" , async ( ) => {
116- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { } ) ) ;
117- await store . deleteChecklist ( 5 , { version : 2 , id : 1 } ) ;
118- expect ( fetchFn . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( "DELETE" ) ;
119- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "/api/items/5/checklist/1" ) ;
107+ it ( "deleteChecklist resolves without error" , async ( ) => {
108+ const store = makeStore ( ( ) => mockResponse ( 200 , { deleted : 7 } ) ) ;
109+ await expect ( store . deleteChecklist ( 5 , { version : 2 , id : 7 } ) ) . resolves . not . toThrow ( ) ;
120110 } ) ;
121111
122- it ( "addComment sends POST to comments endpoint " , async ( ) => {
123- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { id : 1 , body : "Note " } ) ) ;
124- const result = await store . addComment ( 5 , { body : "Note " } ) ;
125- expect ( result . body ) . toBe ( "Note " ) ;
126- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "/api/items/5/comments ") ;
112+ it ( "addComment returns the created comment " , async ( ) => {
113+ const store = makeStore ( ( ) => mockResponse ( 200 , { id : 3 , body : "A note" , author : "agent " } ) ) ;
114+ const comment = await store . addComment ( 5 , { body : "A note " } ) ;
115+ expect ( comment . body ) . toBe ( "A note " ) ;
116+ expect ( comment . author ) . toBe ( "agent ") ;
127117 } ) ;
128118
129- it ( "addDependency sends POST to dependencies endpoint" , async ( ) => {
130- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { } ) ) ;
131- await store . addDependency ( 5 , { version : 1 , depends_on_id : 3 } ) ;
132- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "/api/items/5/dependencies" ) ;
119+ it ( "addDependency resolves without error" , async ( ) => {
120+ const store = makeStore ( ( ) => mockResponse ( 200 , { } ) ) ;
121+ await expect ( store . addDependency ( 5 , { version : 1 , depends_on_id : 3 } ) ) . resolves . not . toThrow ( ) ;
133122 } ) ;
134123
135- it ( "removeDependency sends DELETE to dependency endpoint" , async ( ) => {
136- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , { } ) ) ;
137- await store . removeDependency ( 5 , { version : 2 , depends_on_id : 3 } ) ;
138- expect ( fetchFn . mock . calls [ 0 ] [ 1 ] . method ) . toBe ( "DELETE" ) ;
139- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "/api/items/5/dependencies/3" ) ;
124+ it ( "removeDependency resolves without error" , async ( ) => {
125+ const store = makeStore ( ( ) => mockResponse ( 200 , { } ) ) ;
126+ await expect ( store . removeDependency ( 5 , { version : 2 , depends_on_id : 3 } ) ) . resolves . not . toThrow ( ) ;
140127 } ) ;
141128
142- it ( "listItems with includeArchived=false appends exclude_archived param" , async ( ) => {
143- const { store, fetchFn } = makeTrackedStore ( ( ) => mockResponse ( 200 , [ ] ) ) ;
144- await store . listItems ( null , { includeArchived : false } ) ;
145- expect ( fetchFn . mock . calls [ 0 ] [ 0 ] ) . toContain ( "exclude_archived=1" ) ;
129+ it ( "listItems excludes archived items when asked" , async ( ) => {
130+ const store = makeStore ( ( ) => mockResponse ( 200 , [ { id : 1 , status : "open" } ] ) ) ;
131+ const items = await store . listItems ( null , { includeArchived : false } ) ;
132+ expect ( items ) . toHaveLength ( 1 ) ;
133+ expect ( items [ 0 ] . status ) . toBe ( "open" ) ;
146134 } ) ;
147135} ) ;
148136
0 commit comments