Skip to content

Commit

Permalink
chore: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sashalikesplanes committed Jan 16, 2025
1 parent 0e77644 commit d8a5a4e
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion api-strategy/src/__tests__/nest-local-call.strategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ describe('NestLocalCallStrategy', () => {
createMock<FastifyAdapter>({
inject: (
_opts: string | InjectOptions,
): PartialFuncReturn<Promise<any>> => ({ body: '{}' } as any),
): PartialFuncReturn<Promise<any>> =>
({
body: '{}',
json: () => ({}),
} as any),
}),
},
});
Expand Down Expand Up @@ -86,4 +90,55 @@ describe('NestLocalCallStrategy', () => {
});
expect(result).toBeDefined();
});

it('should skip parsing json if shouldSkipJsonParse is true', async () => {
const instance = new NestLocalCallStrategy(
adapterHost,
clsService,
// @ts-expect-error isnt needed for test
{},
'',
{
shouldSkipJsonParse: (body) => true,
},
);
expect(instance).toBeDefined();

const result = await instance.call('http://localhost:3000', {
method: 'GET',
});

expect(result.data).toEqual('{}');
});

it('should parse json if shouldSkipJsonParse is false', async () => {
const instance = new NestLocalCallStrategy(
adapterHost,
clsService,
// @ts-expect-error isnt needed for test
{},
'',
{
shouldSkipJsonParse: (body) => false,
},
);
expect(instance).toBeDefined();

const result = await instance.call('http://localhost:3000', {
method: 'GET',
});

expect(result.data).toMatchObject({});
});

it('should parse json if shouldSkipJsonParse is undefined', async () => {
const instance = new NestLocalCallStrategy(adapterHost, clsService);
expect(instance).toBeDefined();

const result = await instance.call('http://localhost:3000', {
method: 'GET',
});

expect(result.data).toMatchObject({});
});
});

0 comments on commit d8a5a4e

Please sign in to comment.