Skip to content

Commit

Permalink
stylelistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PodaruDragos committed Nov 25, 2023
1 parent c3570bc commit b6ca0e3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/base_http_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ export class BaseHttpController {
): JsonResult<T> {
return new JsonResult(content, statusCode);
}

protected stream(
readableStream: Readable,
contentType: string,
statusCode: number = StatusCodes.OK
readableStream: Readable,
contentType: string,
statusCode: number = StatusCodes.OK
): StreamResult {
return new StreamResult(readableStream, contentType, statusCode);
}
Expand Down
27 changes: 13 additions & 14 deletions src/results/StreamResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ import { StreamContent } from '../content/streamContent';


export class StreamResult implements IHttpActionResult {
constructor(
public readableStream: Readable,
public contentType: string,
public readonly statusCode: number,
) {
}
constructor(
public readableStream: Readable,
public contentType: string,
public readonly statusCode: number
) { }

public async executeAsync(): Promise<HttpResponseMessage> {
const response = new HttpResponseMessage(this.statusCode);
response.content = new StreamContent(
this.readableStream,
this.contentType,
);
return Promise.resolve(response);
}
public async executeAsync(): Promise<HttpResponseMessage> {
const response = new HttpResponseMessage(this.statusCode);
response.content = new StreamContent(
this.readableStream,
this.contentType,
);
return Promise.resolve(response);
}
}
56 changes: 28 additions & 28 deletions test/content/streamContent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ import { Readable, Writable } from 'stream';
import { StreamContent } from '../../src/content/streamContent';

describe('StreamContent', () => {
it('should have text/plain as the set media type', () => {
const stream = new Readable();
it('should have text/plain as the set media type', () => {
const stream = new Readable();

const content = new StreamContent(stream, 'text/plain');
const content = new StreamContent(stream, 'text/plain');

expect(content.headers['content-type']).toEqual('text/plain');
});
expect(content.headers['content-type']).toEqual('text/plain');
});

it('should be able to pipe stream which was given to it', done => {
const stream = new Readable({
read() {
this.push(Buffer.from('test'));
this.push(null);
},
});
it('should be able to pipe stream which was given to it', done => {
const stream = new Readable({
read() {
this.push(Buffer.from('test'));
this.push(null);
},
});

const content = new StreamContent(stream, 'text/plain');
const content = new StreamContent(stream, 'text/plain');

void content.readAsync().then((readable: Readable) => {
const chunks: Array<Buffer> = [];
void content.readAsync().then((readable: Readable) => {
const chunks: Array<Buffer> = [];

let buffer: Buffer | null = null;
let buffer: Buffer | null = null;

readable.on('end', () => {
buffer = Buffer.concat(chunks);
readable.on('end', () => {
buffer = Buffer.concat(chunks);

expect(buffer.toString()).toEqual('test');
expect(buffer.toString()).toEqual('test');

done();
});
done();
});

const writableStream = new Writable({
write(chunk) {
chunks.push(chunk as Buffer);
},
});
const writableStream = new Writable({
write(chunk) {
chunks.push(chunk as Buffer);
},
});

readable.pipe(writableStream);
});
readable.pipe(writableStream);
});
});
});
11 changes: 2 additions & 9 deletions test/features/decorator_middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@ import * as express from 'express';
import supertest from 'supertest';
import { Container } from 'inversify';
import { METADATA_KEY } from '../../src/constants';
import {
BaseMiddleware,
ControllerMethodMetadata,
InversifyExpressServer,
ControllerMetadata,
} from '../../src/index';
import {
controller, httpGet, httpMethod, httpPut, withMiddleware,
} from '../../src/decorators';
import { BaseMiddleware, ControllerMethodMetadata, InversifyExpressServer, ControllerMetadata } from '../../src/index';
import { controller, httpGet, httpMethod, httpPut, withMiddleware } from '../../src/decorators';
import { cleanUpMetadata } from '../../src/utils';
import assert from 'assert';

Expand Down

0 comments on commit b6ca0e3

Please sign in to comment.