Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ognjenkurtic committed Jan 8, 2024
1 parent 8b81617 commit 29fba71
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { LoggingService } from '../../../../../shared/logging/logging.service';
import { CircuitInputsParserService } from './circuitInputParser.service';

let cips: CircuitInputsParserService;
const loggingServiceMock: DeepMockProxy<LoggingService> = mockDeep<LoggingService>();
const loggingServiceMock: DeepMockProxy<LoggingService> =
mockDeep<LoggingService>();

beforeAll(async () => {
cips = new CircuitInputsParserService(loggingServiceMock);
Expand All @@ -24,67 +25,70 @@ describe('CircuitInputsParserService', () => {

it('Should generate a single circuit input param with charcode sum based on a single string param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"supplierInvoiceID": "INV123"
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": 387 });
expect(circuitInputs).toStrictEqual({ dascircuitinput: 387 });
});

it('Should generate a single circuit input param with charcode sum based on a default value for a missing string param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"somethingElse": ""
}`;

const defaultParamValue = '555333';

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
defaultValue: defaultParamValue
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
defaultValue: defaultParamValue,
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": 312 });
expect(circuitInputs).toStrictEqual({ dascircuitinput: 312 });
});

it('Should return null based on a missing default value for a missing string param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"somethingElse": ""
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'string',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
Expand All @@ -96,92 +100,96 @@ describe('CircuitInputsParserService', () => {

it('Should generate a single circuit input param with charcode sum based on a single string param at root + 1 level', () => {
// Arrange
const payload =
`{
const payload = `{
"supplierInvoice": {
"ID": "INV123"
}
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoice.ID',
dataType: 'string',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoice.ID',
dataType: 'string',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": 387 });
expect(circuitInputs).toStrictEqual({ dascircuitinput: 387 });
});

it('Should generate a single circuit input param based on a single integer param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"supplierInvoiceID": 123
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": 123 });
expect(circuitInputs).toStrictEqual({ dascircuitinput: 123 });
});

it('Should generate a single circuit input param based on a default value for a missing integer param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"somethingElse": ""
}`;

const defaultValue = 555333;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
defaultValue: defaultValue
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
defaultValue: defaultValue,
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": defaultValue });
expect(circuitInputs).toStrictEqual({ dascircuitinput: defaultValue });
});

it('Should return null based on a missing default value for a missing integer param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"somethingElse": ""
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceID',
dataType: 'integer',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
Expand All @@ -193,8 +201,7 @@ describe('CircuitInputsParserService', () => {

it('Should generate a single circuit input param based on a single integer array param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"supplierInvoiceIDs": [
123,
321,
Expand All @@ -203,26 +210,27 @@ describe('CircuitInputsParserService', () => {
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceIDs',
dataType: 'array',
arrayType: 'integer',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceIDs',
dataType: 'array',
arrayType: 'integer',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": [123, 321, 454] });
expect(circuitInputs).toStrictEqual({ dascircuitinput: [123, 321, 454] });
});

it('Should generate a single circuit input param with charcode sums based on a single string array param at root level', () => {
// Arrange
const payload =
`{
const payload = `{
"supplierInvoiceIDs": [
"INV123",
"INV124",
Expand All @@ -231,19 +239,21 @@ describe('CircuitInputsParserService', () => {
}`;

const schema = {
mapping: [{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceIDs',
dataType: 'array',
arrayType: 'string',
} as CircuitInputMapping]
mapping: [
{
circuitInput: 'dascircuitinput',
description: 'desc',
payloadJsonPath: 'supplierInvoiceIDs',
dataType: 'array',
arrayType: 'string',
} as CircuitInputMapping,
],
} as CircuitInputsMapping;

// Act
const circuitInputs = cips.applyMappingToJSONPayload(payload, schema);

// Assert
expect(circuitInputs).toStrictEqual({ "dascircuitinput": [387, 388, 389] });
expect(circuitInputs).toStrictEqual({ dascircuitinput: [387, 388, 389] });
});
});
Loading

0 comments on commit 29fba71

Please sign in to comment.