Skip to content

Commit

Permalink
fix(Bunny): purge method fixed
Browse files Browse the repository at this point in the history
purge was implemented incorrectly and it's refactor caused a signature change on hardUpdate.
Technically a breaking change but since it never worked...

closes #1
  • Loading branch information
stonelasley committed Oct 3, 2018
1 parent 64e3f4b commit 258ec60
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ bunny.purge('http://my-zone/mypath/filetopurge.css');

HardUpdate File (Update and Purge)
``` javascript
bunny.hardUpdate('http://my-zone/mypath/filetopurge.css', 'file contents');
bunny.hardUpdate('https://mydomain.com','myStorage', 'myPath', 'fileName.css', 'new file contents');
```
22 changes: 14 additions & 8 deletions src/bunny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ export class Bunny extends HttpBase {
}

async purge(url: string): Promise<void> {
await super.post(
`${Resource.PullZone}/${Endpoint.Purge}?${Parameter.URL}=${url}`,
null,
await super.post(`${Endpoint.Purge}?${Parameter.URL}=${url}`, null);
}

async hardUpdate(
host: string,
storageZone: string,
path: string,
fileName: string,
fileContents: string,
): Promise<void> {
await this.storage.update(
`${storageZone}/${path}/${fileName}`,
fileContents,
);
}

async hardUpdate(filePath: string, fileContents: string): Promise<void> {
await this.storage.update(filePath, fileContents);
await this.purge(filePath);
await this.purge(`${host}/${path}/${fileName}`);
}
}
27 changes: 17 additions & 10 deletions test/bunny.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('Bunny', () => {
.purge(url)
.then(() => {
expect(axios.post).toHaveBeenCalledWith(
`pullzone/purge?url=${url}`,
`purge?url=${url}`,
null,
validateConfig,
);
Expand All @@ -142,16 +142,23 @@ describe('Bunny', () => {
});

it('should update and then purge file', done => {
const fullPath = 'myzone/somepath/afile.js';
const host = 'https://www.myhost.com';
const path = 'somePath';
const storageZone = 'myzone';
const fileName = 'afile.js';
const fileContents = 'some contents';
classUnderTest.hardUpdate(fullPath, fileContents).then(() => {
expect(classUnderTest.storage.update).toHaveBeenCalledWith(
fullPath,
fileContents,
);
expect(classUnderTest.purge).toHaveBeenCalledWith(fullPath);
done();
});
classUnderTest
.hardUpdate(host, storageZone, path, fileName, fileContents)
.then(() => {
expect(classUnderTest.storage.update).toHaveBeenCalledWith(
'myzone/somePath/afile.js',
fileContents,
);
expect(classUnderTest.purge).toHaveBeenCalledWith(
'https://www.myhost.com/somePath/afile.js',
);
done();
});
});
});
});

0 comments on commit 258ec60

Please sign in to comment.