Skip to content

Commit

Permalink
cleaned up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Jan 3, 2020
1 parent 1457a5a commit 19063db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
25 changes: 10 additions & 15 deletions x-pack/legacy/plugins/alerting/server/routes/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mockedAlert = {
params: {
bar: true,
},
throttle: '30s',
actions: [
{
group: 'default',
Expand All @@ -31,17 +32,6 @@ const mockedAlert = {
],
};

const mockedAlertComputerFields = {
enabled: true,
muteAll: false,
createdBy: '',
updatedBy: '',
apiKey: '',
apiKeyOwner: '',
throttle: '30s',
mutedInstanceIds: [],
};

beforeEach(() => jest.resetAllMocks());

test('creates an alert with proper parameters', async () => {
Expand All @@ -55,7 +45,13 @@ test('creates an alert with proper parameters', async () => {
const updatedAt = new Date();
alertsClient.create.mockResolvedValueOnce({
...mockedAlert,
...mockedAlertComputerFields,
enabled: true,
muteAll: false,
createdBy: '',
updatedBy: '',
apiKey: '',
apiKeyOwner: '',
mutedInstanceIds: [],
createdAt,
updatedAt,
id: '123',
Expand All @@ -70,7 +66,7 @@ test('creates an alert with proper parameters', async () => {
expect(statusCode).toBe(200);
const response = JSON.parse(payload);
expect(new Date(response.createdAt)).toEqual(createdAt);
expect(omit(response, 'createdAt')).toMatchInlineSnapshot(`
expect(omit(response, 'createdAt', 'updatedAt')).toMatchInlineSnapshot(`
Object {
"actions": Array [
Object {
Expand Down Expand Up @@ -102,7 +98,6 @@ test('creates an alert with proper parameters', async () => {
"foo",
],
"throttle": "30s",
"updatedAt": null,
"updatedBy": "",
}
`);
Expand Down Expand Up @@ -133,7 +128,7 @@ test('creates an alert with proper parameters', async () => {
"tags": Array [
"foo",
],
"throttle": null,
"throttle": "30s",
},
},
]
Expand Down
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/alerting/server/routes/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ test('calls get with proper parameters', async () => {
alertsClient.get.mockResolvedValueOnce(mockedAlert);
const { payload, statusCode } = await server.inject(request);
expect(statusCode).toBe(200);
const { createdAt, ...response } = JSON.parse(payload);
expect({ createdAt: new Date(createdAt), ...response }).toEqual(mockedAlert);
const { createdAt, updatedAt, ...response } = JSON.parse(payload);
expect({ createdAt: new Date(createdAt), updatedAt: new Date(updatedAt), ...response }).toEqual(
mockedAlert
);
expect(alertsClient.get).toHaveBeenCalledTimes(1);
expect(alertsClient.get.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Expand Down

0 comments on commit 19063db

Please sign in to comment.