diff --git a/README.md b/README.md index 5d540dd..0122e7d 100644 --- a/README.md +++ b/README.md @@ -65,5 +65,10 @@ const stats : Statistic = await bunny.statistics(); Purge File Cache ``` javascript -await bunny.purge('http://my-zone/mypath/filetopurge.css'); +bunny.purge('http://my-zone/mypath/filetopurge.css'); +``` + +HardUpdate File (Update and Purge) +``` javascript +bunny.hardUpdate('http://my-zone/mypath/filetopurge.css', 'file contents'); ``` diff --git a/src/bunny.ts b/src/bunny.ts index 6a11c44..1233e6b 100644 --- a/src/bunny.ts +++ b/src/bunny.ts @@ -47,4 +47,9 @@ export class Bunny extends HttpBase { null, ); } + + async hardUpdate(filePath: string, fileContents: string): Promise { + await this.storage.update(filePath, fileContents); + await this.purge(filePath); + } } diff --git a/test/bunny.spec.ts b/test/bunny.spec.ts index f8d4ce7..7614c16 100644 --- a/test/bunny.spec.ts +++ b/test/bunny.spec.ts @@ -129,4 +129,29 @@ describe('Bunny', () => { .catch(err => console.error('ERROR', err)); }); }); + + describe('hardUpdate', () => { + beforeEach(() => { + jest + .spyOn(classUnderTest.storage, 'update') + .mockReturnValueOnce(Promise.resolve({})); + + jest + .spyOn(classUnderTest, 'purge') + .mockReturnValueOnce(Promise.resolve({})); + }); + + it('should update and then purge file', done => { + const fullPath = 'myzone/somepath/afile.js'; + const fileContents = 'some contents'; + classUnderTest.hardUpdate(fullPath, fileContents).then(() => { + expect(classUnderTest.storage.update).toHaveBeenCalledWith( + fullPath, + fileContents, + ); + expect(classUnderTest.purge).toHaveBeenCalledWith(fullPath); + done(); + }); + }); + }); });