insomnia/packages/insomnia-app/app/models/__tests__/grpc-request.test.ts
Filipe Freire f513d59f69
Add gRPC Headers (INS-362) (#3667) (#4244)
* Add gRPC Headers (INS-362) (#3667)

* Add grpc headers support to client, server and bidi streams

* Fix failing grpc unit checks

* Improvements after CR for #4244

* Fix lint issues

* Fix grpc header overflow and failing tests

* Fix illegal characters in metadata key validation

* Fix common-headers naming and add unit checks

* Fix wrong import format
2021-12-06 10:12:18 +00:00

65 lines
1.6 KiB
TypeScript

import { globalBeforeEach } from '../../__jest__/before-each';
import * as models from '../index';
describe('init()', () => {
beforeEach(globalBeforeEach);
it('contains all required fields', async () => {
Date.now = jest.fn().mockReturnValue(1478795580200);
expect(models.grpcRequest.init()).toEqual({
url: '',
name: 'New gRPC Request',
description: '',
protoFileId: '',
protoMethodName: '',
metadata: [],
body: {
text: '{}',
},
metaSortKey: -1478795580200,
isPrivate: false,
});
});
});
describe('create()', () => {
beforeEach(globalBeforeEach);
it('creates a valid GrpcRequest', async () => {
Date.now = jest.fn().mockReturnValue(1478795580200);
const request = await models.grpcRequest.create({
name: 'My request',
parentId: 'fld_124',
});
const expected = {
_id: 'greq_cc1dd2ca4275747aa88199e8efd42403',
created: 1478795580200,
modified: 1478795580200,
parentId: 'fld_124',
name: 'My request',
description: '',
url: '',
protoFileId: '',
protoMethodName: '',
metadata: [],
body: {
text: '{}',
},
metaSortKey: -1478795580200,
isPrivate: false,
type: 'GrpcRequest',
};
expect(request).toEqual(expected);
expect(await models.grpcRequest.getById(expected._id)).toEqual(expected);
});
it('fails when missing parentId', async () => {
Date.now = jest.fn().mockReturnValue(1478795580200);
expect(() =>
models.grpcRequest.create({
name: 'no parentId',
}),
).toThrow('New GrpcRequest missing `parentId`');
});
});