Skip to content

Commit

Permalink
feat(Bunny): hardUpdate method to update file and purge cache
Browse files Browse the repository at this point in the history
  • Loading branch information
stonelasley committed Oct 2, 2018
1 parent b66366b commit 64e3f4b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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');
```
5 changes: 5 additions & 0 deletions src/bunny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ export class Bunny extends HttpBase {
null,
);
}

async hardUpdate(filePath: string, fileContents: string): Promise<void> {
await this.storage.update(filePath, fileContents);
await this.purge(filePath);
}
}
25 changes: 25 additions & 0 deletions test/bunny.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});

0 comments on commit 64e3f4b

Please sign in to comment.