Skip to content

Commit

Permalink
add test case for json input
Browse files Browse the repository at this point in the history
  • Loading branch information
khavishbhundoo committed May 24, 2024
1 parent 19861d5 commit c60d144
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/CallMyTrade.Api.AcceptanceTests/tests/tradingview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const schema = z.object({

const ENDPOINT = '/webhook/tradingview';

describe(`POST Request ${HOST}${ENDPOINT} with plain text`, () => {
describe(`POST successful request ${HOST}${ENDPOINT} with plain text`, () => {
let response: Response;
let body: { [key: string]: unknown };

Expand All @@ -35,6 +35,35 @@ describe(`POST Request ${HOST}${ENDPOINT} with plain text`, () => {
expect(response.headers.get('Content-Type')).toBe('application/json; charset=utf-8');
});

test('Should have valid body schema', () => {
expect(() => schema.parse(body)).not.toThrowError();
});
});

describe(`POST successful request ${HOST}${ENDPOINT} with JSON`, () => {
let response: Response;
let body: { [key: string]: unknown };

beforeAll(async () => {
const url = `${HOST}${ENDPOINT}`;
response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'text/plain'
},
body: JSON.stringify({text: 'BTCUSD Greater Than 9000'})
});
body = await response.json();
}, BEFORE_ALL_TIMEOUT);

test('Should have response status 201', () => {
expect(response.status).toBe(201);
});

test('Should have content-type = application/json', () => {
expect(response.headers.get('Content-Type')).toBe('application/json; charset=utf-8');
});

test('Should have valid body schema', () => {
expect(() => schema.parse(body)).not.toThrowError();
});
Expand Down

0 comments on commit c60d144

Please sign in to comment.