2020-10-28 00:05:54 +00:00
|
|
|
import { globalBeforeEach } from '../../__jest__/before-each';
|
2021-07-22 23:04:56 +00:00
|
|
|
import * as models from '../index';
|
2020-10-28 00:05:54 +00:00
|
|
|
|
|
|
|
describe('init()', () => {
|
|
|
|
beforeEach(globalBeforeEach);
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2020-10-28 00:05:54 +00:00
|
|
|
it('contains all required fields', async () => {
|
|
|
|
Date.now = jest.fn().mockReturnValue(1478795580200);
|
|
|
|
expect(models.grpcRequest.init()).toEqual({
|
|
|
|
url: '',
|
|
|
|
name: 'New gRPC Request',
|
2020-10-28 23:00:29 +00:00
|
|
|
description: '',
|
2020-10-28 00:05:54 +00:00
|
|
|
protoFileId: '',
|
|
|
|
protoMethodName: '',
|
2021-12-06 10:12:18 +00:00
|
|
|
metadata: [],
|
2020-11-12 23:03:36 +00:00
|
|
|
body: {
|
|
|
|
text: '{}',
|
|
|
|
},
|
2020-10-28 00:05:54 +00:00
|
|
|
metaSortKey: -1478795580200,
|
2021-05-12 06:35:00 +00:00
|
|
|
isPrivate: false,
|
2020-10-28 00:05:54 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('create()', () => {
|
|
|
|
beforeEach(globalBeforeEach);
|
2021-05-12 06:35:00 +00:00
|
|
|
|
2020-10-28 00:05:54 +00:00
|
|
|
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',
|
2020-10-28 23:00:29 +00:00
|
|
|
description: '',
|
2020-10-28 00:05:54 +00:00
|
|
|
url: '',
|
|
|
|
protoFileId: '',
|
|
|
|
protoMethodName: '',
|
2021-12-06 10:12:18 +00:00
|
|
|
metadata: [],
|
2020-11-12 23:03:36 +00:00
|
|
|
body: {
|
|
|
|
text: '{}',
|
|
|
|
},
|
2020-10-28 00:05:54 +00:00
|
|
|
metaSortKey: -1478795580200,
|
2021-05-12 06:35:00 +00:00
|
|
|
isPrivate: false,
|
2020-10-28 00:05:54 +00:00
|
|
|
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);
|
2021-05-12 06:35:00 +00:00
|
|
|
expect(() =>
|
|
|
|
models.grpcRequest.create({
|
|
|
|
name: 'no parentId',
|
|
|
|
}),
|
|
|
|
).toThrow('New GrpcRequest missing `parentId`');
|
2020-10-28 00:05:54 +00:00
|
|
|
});
|
|
|
|
});
|