Skip to content

Commit

Permalink
comply with new template parser construct mockoon#83
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru89 committed May 19, 2024
1 parent 1f596cf commit ff90d8a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 106 deletions.
18 changes: 13 additions & 5 deletions packages/commons-server/src/libs/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,14 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
route: Route,
enabledRouteResponse: RouteResponse,
request?: IncomingMessage,
data?: string
data?: string,
connectedRequest?: ServerRequest
): string | undefined {
let content: any = enabledRouteResponse.body;
let finalRequest = connectedRequest;
if (!finalRequest) {
finalRequest = request ? fromWsRequest(request, data) : undefined;
}

if (
enabledRouteResponse.bodyType === BodyTypes.DATABUCKET &&
Expand Down Expand Up @@ -796,7 +801,7 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
environment: this.environment,
processedDatabuckets: this.processedDatabuckets,
globalVariables: this.globalVariables,
request: request ? fromWsRequest(request, data) : undefined,
request: finalRequest,
envVarsPrefix: this.options.envVarsPrefix
});

Expand Down Expand Up @@ -828,7 +833,7 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
environment: this.environment,
processedDatabuckets: this.processedDatabuckets,
globalVariables: this.globalVariables,
request: request ? fromWsRequest(request, data) : undefined,
request: finalRequest,
envVarsPrefix: this.options.envVarsPrefix
});
}
Expand All @@ -848,12 +853,15 @@ export class MockoonServer extends (EventEmitter as new () => TypedEmitter<Serve
_: number,
enabledRouteResponse: RouteResponse
) => {
// todo
// todo: do we need to take params from initial connection at all?
const content =
this.deriveFinalResponseContentForWebSockets(
socket,
route,
enabledRouteResponse
enabledRouteResponse,
undefined,
undefined,
request
) || '';

if (!content) {
Expand Down
78 changes: 39 additions & 39 deletions packages/commons/test/migrations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,45 +458,6 @@ describe('Migrations', () => {
});
});

describe('migration n. 33', () => {
it('should have set default websocket specifics to existing routes', () => {
const environment0: any = {};
const environment1: any = { routes: [{}] };
const environment2: any = { routes: [{ uuid: 'abc' }, { uuid: 'abc2' }] };

applyMigration(33, environment0);
applyMigration(33, environment1);
applyMigration(33, environment2);

strictEqual(environment0.routes, undefined);
notStrictEqual(environment1.routes[0], undefined);
strictEqual(
environment1.routes[0].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment1.routes[0].streamingInterval,
RouteDefault.streamingInterval
);
strictEqual(
environment2.routes[0].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment2.routes[0].streamingInterval,
RouteDefault.streamingInterval
);
strictEqual(
environment2.routes[1].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment2.routes[1].streamingInterval,
RouteDefault.streamingInterval
);
});
});

describe('migration n. 31', () => {
it('should remove route toggling and return the list of disabled route uuids', () => {
const environment1: any = {
Expand Down Expand Up @@ -596,4 +557,43 @@ describe('Migrations', () => {
});
});
});

describe('migration n. 33', () => {
it('should have set default websocket specifics to existing routes', () => {
const environment0: any = {};
const environment1: any = { routes: [{}] };
const environment2: any = { routes: [{ uuid: 'abc' }, { uuid: 'abc2' }] };

applyMigration(33, environment0);
applyMigration(33, environment1);
applyMigration(33, environment2);

strictEqual(environment0.routes, undefined);
notStrictEqual(environment1.routes[0], undefined);
strictEqual(
environment1.routes[0].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment1.routes[0].streamingInterval,
RouteDefault.streamingInterval
);
strictEqual(
environment2.routes[0].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment2.routes[0].streamingInterval,
RouteDefault.streamingInterval
);
strictEqual(
environment2.routes[1].streamingMode,
RouteDefault.streamingMode
);
strictEqual(
environment2.routes[1].streamingInterval,
RouteDefault.streamingInterval
);
});
});
});
82 changes: 20 additions & 62 deletions packages/desktop/package-lock.json

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

0 comments on commit ff90d8a

Please sign in to comment.