Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Apr 15, 2020
1 parent 3e6ff51 commit f2f1134
Show file tree
Hide file tree
Showing 4 changed files with 728 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const COMMENT_URL = `api/now/${API_VERSION}/table/incident`;
// Based on: https://docs.servicenow.com/bundle/orlando-platform-user-interface/page/use/navigation/reference/r_NavigatingByURLExamples.html
const VIEW_INCIDENT_URL = `nav_to.do?uri=incident.do?sys_id=`;

const getErrorMessage = (msg: string) => {
export const getErrorMessage = (msg: string) => {
return `[Action][ServiceNow]: ${msg}`;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { informationCreated, informationUpdated, informationAdded, append } from './transformers';

describe('informationCreated', () => {
test('transforms correctly', () => {
const res = informationCreated({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
});
expect(res).toEqual({ value: 'a value (created at 2020-04-15T08:19:27.400Z by elastic)' });
});

test('transforms correctly without optional fields', () => {
const res = informationCreated({
value: 'a value',
});
expect(res).toEqual({ value: 'a value (created at by )' });
});

test('returns correctly rest fields', () => {
const res = informationCreated({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
previousValue: 'previous value',
});
expect(res).toEqual({
value: 'a value (created at 2020-04-15T08:19:27.400Z by elastic)',
previousValue: 'previous value',
});
});
});

describe('informationUpdated', () => {
test('transforms correctly', () => {
const res = informationUpdated({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
});
expect(res).toEqual({ value: 'a value (updated at 2020-04-15T08:19:27.400Z by elastic)' });
});

test('transforms correctly without optional fields', () => {
const res = informationUpdated({
value: 'a value',
});
expect(res).toEqual({ value: 'a value (updated at by )' });
});

test('returns correctly rest fields', () => {
const res = informationUpdated({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
previousValue: 'previous value',
});
expect(res).toEqual({
value: 'a value (updated at 2020-04-15T08:19:27.400Z by elastic)',
previousValue: 'previous value',
});
});
});

describe('informationAdded', () => {
test('transforms correctly', () => {
const res = informationAdded({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
});
expect(res).toEqual({ value: 'a value (added at 2020-04-15T08:19:27.400Z by elastic)' });
});

test('transforms correctly without optional fields', () => {
const res = informationAdded({
value: 'a value',
});
expect(res).toEqual({ value: 'a value (added at by )' });
});

test('returns correctly rest fields', () => {
const res = informationAdded({
value: 'a value',
date: '2020-04-15T08:19:27.400Z',
user: 'elastic',
previousValue: 'previous value',
});
expect(res).toEqual({
value: 'a value (added at 2020-04-15T08:19:27.400Z by elastic)',
previousValue: 'previous value',
});
});
});

describe('append', () => {
test('transforms correctly', () => {
const res = append({
value: 'a value',
previousValue: 'previous value',
});
expect(res).toEqual({ value: 'previous value \r\na value' });
});

test('transforms correctly without optional fields', () => {
const res = append({
value: 'a value',
});
expect(res).toEqual({ value: 'a value' });
});

test('returns correctly rest fields', () => {
const res = append({
value: 'a value',
user: 'elastic',
previousValue: 'previous value',
});
expect(res).toEqual({
value: 'previous value \r\na value',
user: 'elastic',
});
});
});
Loading

0 comments on commit f2f1134

Please sign in to comment.