Skip to content

Commit

Permalink
test: adds test to check rxjs support
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Jan 28, 2021
1 parent 1c8ee54 commit cf62063
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions integration/send-files/e2e/express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ describe('Express FileSend', () => {
.expect(200)
.expect({ value: 'Hello world' });
});
it('should return a file from an RxJS stream', async () => {
return request(app.getHttpServer())
.get('/file/rxjs/stream/')
.expect(200)
.expect((res) => {
expect(res.body.toString()).to.be.eq(readmeString);
});
});
});
8 changes: 8 additions & 0 deletions integration/send-files/e2e/fastify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ describe('Fastify FileSend', () => {
expect(payload).to.be.eq({ value: 'Hello world' });
});
});
it('should return a file from an RxJS stream', async () => {
return app.inject({
method: 'GET',
url: '/file/rxjs/stream'
}).then(({ payload }) => {
expect(payload.toString()).to.be.eq(readmeString);
});
});
});
6 changes: 6 additions & 0 deletions integration/send-files/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, Get, StreamableFile } from '@nestjs/common';
import { Observable } from 'rxjs';
import { AppService } from './app.service';
import { NonFile } from './non-file';

Expand All @@ -20,4 +21,9 @@ export class AppController {
getNonFile(): NonFile {
return this.appService.getNonFile();
}

@Get('file/rxjs/stream')
getRxJSFile(): Observable<StreamableFile> {
return this.appService.getRxJSFile();
}
}
5 changes: 5 additions & 0 deletions integration/send-files/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, StreamableFile } from '@nestjs/common';
import { createReadStream, readFileSync } from 'fs';
import { join } from 'path';
import { Observable, of } from 'rxjs';
import { NonFile } from './non-file';

@Injectable()
Expand All @@ -18,4 +19,8 @@ export class AppService {
getNonFile(): NonFile {
return new NonFile('Hello world');
}

getRxJSFile(): Observable<StreamableFile> {
return of(this.getReadStream());
}
}

0 comments on commit cf62063

Please sign in to comment.