Skip to content

Commit

Permalink
fix(abc:down-file): fix don't verify http status code, close #44
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk committed Mar 13, 2018
1 parent e25d2b6 commit 07319c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/abc/down-file/down-file.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DownFileDirective {
responseType: 'blob',
observe: 'response'
}).subscribe((res: HttpResponse<Blob>) => {
if (res.body.size <= 0) {
if (res.status !== 200 || res.body.size <= 0) {
this.error.emit(res);
return;
}
Expand Down
13 changes: 13 additions & 0 deletions src/core/abc/down-file/down-file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ describe('abc: down-file', () => {
ret.flush(genFile('docx', false));
expect(context.error).toHaveBeenCalled();
});

it('should be throw error when http status is not 200', () => {
spyOn(fs, 'saveAs');
spyOn(context, 'error');
expect(context.error).not.toHaveBeenCalled();
expect(fs.saveAs).not.toHaveBeenCalled();
(dl.query(By.css('#down-docx')).nativeElement as HTMLButtonElement).click();
const ret = httpBed
.expectOne(req => req.url.startsWith('/')) as TestRequest;
ret.flush(null, { status: 201, statusText: '201' });
expect(fs.saveAs).not.toHaveBeenCalled();
expect(context.error).toHaveBeenCalled();
});
});

@Component({
Expand Down

0 comments on commit 07319c4

Please sign in to comment.