@@ -14,6 +14,7 @@ import DAVEventListener from "../../../src/models/davEventListener.js";
1414import { DavObject } from "../../../src/models/davObject.js" ;
1515import * as XMLUtility from '../../../src/utility/xmlUtility.js' ;
1616import RequestMock from "../../mocks/request.mock.js" ;
17+ import NetworkRequestServerError from '../../../src/errors/networkRequestServerError.js'
1718
1819describe ( 'Dav collection model' , ( ) => {
1920
@@ -693,6 +694,95 @@ describe('Dav collection model', () => {
693694 } ) ;
694695 } ) ;
695696
697+ it ( 'should clear the internal list of changed properties after a successful update' , async ( ) => {
698+ const parent = {
699+ 'findAll' : vi . fn ( ) ,
700+ 'findAllByFilter' : vi . fn ( ) ,
701+ 'find' : vi . fn ( ) ,
702+ 'createCollection' : vi . fn ( ) ,
703+ 'createObject' : vi . fn ( ) ,
704+ 'update' : vi . fn ( ) ,
705+ 'delete' : vi . fn ( ) ,
706+ 'isReadable' : vi . fn ( ) ,
707+ 'isWriteable' : vi . fn ( )
708+ } ;
709+ const request = new RequestMock ( ) ;
710+ const url = '/foo/bar/folder' ;
711+ const props = {
712+ '{DAV:}displayname' : 'Foo Bar Bla Blub' ,
713+ '{DAV:}owner' : 'https://foo/bar/' ,
714+ '{DAV:}resourcetype' : [ '{DAV:}collection' ] ,
715+ '{DAV:}sync-token' : 'https://foo/bar/token/3' ,
716+ '{custom}property' : 'custom property value 123' ,
717+ '{DAV:}current-user-privilege-set' : [ '{DAV:}write' ,
718+ '{DAV:}write-properties' , '{DAV:}write-content' ,
719+ '{DAV:}unlock' , '{DAV:}bind' , '{DAV:}unbind' ,
720+ '{DAV:}write-acl' , '{DAV:}read' , '{DAV:}read-acl' ,
721+ '{DAV:}read-current-user-privilege-set' ] ,
722+ } ;
723+
724+ request . propPatch . mockImplementation ( ( ) => {
725+ return Promise . resolve ( {
726+ status : 207 ,
727+ body : {
728+ '{DAV:}displayname' : 'test' ,
729+ '{http://apple.com/ns/ical/}calendar-color' : ''
730+ } ,
731+ headers : { }
732+ } ) ;
733+ } ) ;
734+
735+ const collection = new DavCollection ( parent , request , url , props ) ;
736+ collection . displayname = 'test' ;
737+
738+ await collection . update ( ) ;
739+ await collection . update ( ) ;
740+ await collection . update ( ) ;
741+
742+ expect ( request . propPatch ) . toHaveBeenCalledTimes ( 1 ) ;
743+ } ) ;
744+
745+ it ( 'should not clear the internal list of changed properties after an unsuccessful update' , async ( ) => {
746+ const parent = {
747+ 'findAll' : vi . fn ( ) ,
748+ 'findAllByFilter' : vi . fn ( ) ,
749+ 'find' : vi . fn ( ) ,
750+ 'createCollection' : vi . fn ( ) ,
751+ 'createObject' : vi . fn ( ) ,
752+ 'update' : vi . fn ( ) ,
753+ 'delete' : vi . fn ( ) ,
754+ 'isReadable' : vi . fn ( ) ,
755+ 'isWriteable' : vi . fn ( )
756+ } ;
757+ const request = new RequestMock ( ) ;
758+ const url = '/foo/bar/folder' ;
759+ const props = {
760+ '{DAV:}displayname' : 'Foo Bar Bla Blub' ,
761+ '{DAV:}owner' : 'https://foo/bar/' ,
762+ '{DAV:}resourcetype' : [ '{DAV:}collection' ] ,
763+ '{DAV:}sync-token' : 'https://foo/bar/token/3' ,
764+ '{custom}property' : 'custom property value 123' ,
765+ '{DAV:}current-user-privilege-set' : [ '{DAV:}write' ,
766+ '{DAV:}write-properties' , '{DAV:}write-content' ,
767+ '{DAV:}unlock' , '{DAV:}bind' , '{DAV:}unbind' ,
768+ '{DAV:}write-acl' , '{DAV:}read' , '{DAV:}read-acl' ,
769+ '{DAV:}read-current-user-privilege-set' ] ,
770+ } ;
771+
772+ request . propPatch . mockImplementation ( ( ) => {
773+ return Promise . reject ( new NetworkRequestServerError ( { status : 500 } ) ) ;
774+ } ) ;
775+
776+ const collection = new DavCollection ( parent , request , url , props ) ;
777+ collection . displayname = 'test' ;
778+
779+ await expect ( collection . update ( ) ) . rejects . toThrow ( ) ;
780+ await expect ( collection . update ( ) ) . rejects . toThrow ( ) ;
781+ await expect ( collection . update ( ) ) . rejects . toThrow ( ) ;
782+
783+ expect ( request . propPatch ) . toHaveBeenCalledTimes ( 3 ) ;
784+ } ) ;
785+
696786 it ( 'should delete a collection' , ( ) => {
697787 const parent = {
698788 'findAll' : vi . fn ( ) ,
0 commit comments