Skip to content

Commit

Permalink
Integrate Changes
Browse files Browse the repository at this point in the history
Integrate Changes
  • Loading branch information
gabrielforster authored May 2, 2024
2 parents 6811c9e + 572ec45 commit 4eec884
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ dist
coverage
.env
build

.tool-versions
1 change: 0 additions & 1 deletion __tests__/date/date.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ describe('getDiffDays', () => {
expect(getDiffDays(param.date)).toBe(param.output)
})
})

106 changes: 53 additions & 53 deletions __tests__/entitySchema/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { EntitySchema } from '../../src/entitySchema';
import { EntitySchema } from '../../src/entitySchema'

describe('assembleEntitySchema', () => {
const validDefaultsObjects = [
{
solicitation: {
appId: true,
jsonData: {
address: true,
},
address: true
}
},
entitySchema: {
appId: {
type: 'string',
occult: false,
required: true,
label: 'Portal',
label: 'Portal'
},
jsonData: {
type: 'object',
Expand All @@ -26,7 +26,7 @@ describe('assembleEntitySchema', () => {
type: 'string',
occult: false,
required: true,
label: 'Ocorrência',
label: 'Ocorrência'
},
address: {
type: 'object',
Expand All @@ -38,17 +38,17 @@ describe('assembleEntitySchema', () => {
type: 'string',
occult: false,
required: true,
label: 'Estado',
label: 'Estado'
},
city: {
type: 'string',
occult: false,
required: true,
label: 'Cidade',
},
},
},
},
label: 'Cidade'
}
}
}
}
},
test: {
type: 'array',
Expand All @@ -59,16 +59,16 @@ describe('assembleEntitySchema', () => {
type: 'string',
occult: false,
required: true,
label: 'Ocorrência',
},
},
label: 'Ocorrência'
}
}
},
returnExpected: {
appId: {
type: 'string',
occult: false,
required: true,
label: 'Portal',
label: 'Portal'
},
jsonData: {
type: 'object',
Expand All @@ -86,46 +86,46 @@ describe('assembleEntitySchema', () => {
type: 'string',
occult: false,
required: true,
label: 'Estado',
label: 'Estado'
},
city: {
type: 'string',
occult: false,
required: true,
label: 'Cidade',
},
},
},
},
},
},
label: 'Cidade'
}
}
}
}
}
}
},
{
solicitation: {
jsonData: true,
jsonData: true
},
entitySchema: {
appId: {
type: 'string',
occult: false,
required: true,
label: 'Portal',
},
label: 'Portal'
}
},
returnExpected: {},
returnExpected: {}
},
{
solicitation: {
appId: true,
appId: true
},
entitySchema: undefined,
returnExpected: {},
returnExpected: {}
},
{
solicitation: {
test: {
children1: true,
},
children1: true
}
},
entitySchema: {
test: {
Expand All @@ -138,51 +138,51 @@ describe('assembleEntitySchema', () => {
type: 'string',
occult: false,
required: true,
label: 'teste',
label: 'teste'
},
children2: {
type: 'string',
occult: false,
required: true,
label: 'teste',
},
},
},
label: 'teste'
}
}
}
},
returnExpected: {
test: {
contentArray: {
children1: {
label: "teste",
label: 'teste',
occult: false,
required: true,
type: "string",
type: 'string'
},
children2: {
label: "teste",
label: 'teste',
occult: false,
required: true,
type: "string",
},
type: 'string'
}
},
contentObject: {
children1: {
label: "teste",
label: 'teste',
occult: false,
required: true,
type: "string",
},
type: 'string'
}
},
label: "teste",
label: 'teste',
occult: false,
required: true,
type: "array",
},
},
},
];
type: 'array'
}
}
}
]

test.each(validDefaultsObjects)('should returns validation of the provided specific entity schema', ({ solicitation, entitySchema, returnExpected }) => {
expect(EntitySchema.assembleEntitySchema(solicitation, entitySchema)).toEqual(returnExpected);
});
});
expect(EntitySchema.assembleEntitySchema(solicitation, entitySchema)).toEqual(returnExpected)
})
})
12 changes: 6 additions & 6 deletions __tests__/error/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { error } from '../../src/error';
import { error } from '../../src/error'

describe('error', () => {
it('Should format error with a error object', () => {
expect(error(400, { id: undefined })).toEqual({ statusCode: 400, error: { id: undefined } });
});
expect(error(400, { id: undefined })).toEqual({ statusCode: 400, error: { id: undefined } })
})

it('Should format error with a error string', () => {
expect(error(400, 'Incorrect id value')).toEqual({ statusCode: 400, message: 'Incorrect id value' });
});
});
expect(error(400, 'Incorrect id value')).toEqual({ statusCode: 400, message: 'Incorrect id value' })
})
})
8 changes: 4 additions & 4 deletions __tests__/lambda/lambdaService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('invoke', () => {
})).resolves.toEqual({status: 400, body: { code: 'undefined' }});
*/
});
})

it('Should returns the function invoked with error', async () => {
/**
Expand All @@ -35,7 +35,7 @@ describe('invoke', () => {
isOffline: false,
})).rejects.toBeTruthy();
**/
});
})

it('Should returns error to invoke without optional properties', async () => {
/**
Expand All @@ -44,5 +44,5 @@ describe('invoke', () => {
functionName: 'authenticate-api-generalValidateSession',
})).rejects.toBeTruthy();
**/
});
});
})
})
2 changes: 0 additions & 2 deletions __tests__/s3/formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,4 @@ describe('streamToString', () => {
const result = await streamToString(readable)
expect(result).toEqual(jsonString)
})


})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adapcon-utils-js",
"version": "1.4.0",
"version": "1.4.1",
"description": "Utils library for Javascript",
"keywords": [],
"author": {
Expand Down
39 changes: 20 additions & 19 deletions src/entitySchema/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
export const EntitySchema = {
assembleEntitySchema(solicitation: any, entitySchema: any): object {
const defaultObject = {};
const properties = Object.keys(solicitation);
assembleEntitySchema (solicitation: any, entitySchema: any): object {
const defaultObject = {}
const properties = Object.keys(solicitation)

properties.forEach(key => {
if (entitySchema === undefined) return;
const haveChildren = typeof solicitation[key] === 'object';
const property = entitySchema[key];
properties.forEach(key => {
if (entitySchema === undefined) return
const haveChildren = typeof solicitation[key] === 'object'
const property = entitySchema[key]

if (property === undefined) return;
if (property === undefined) return

if (haveChildren) {
defaultObject[key] = {
...property,
contentObject: {
...EntitySchema.assembleEntitySchema(solicitation[key], property.contentObject || property.contentArray),
},
};
} else defaultObject[key] = property;
});
if (haveChildren) {
defaultObject[key] = {
...property,
contentObject: {
...EntitySchema.assembleEntitySchema(solicitation[key], property.contentObject || property.contentArray)
}
}
} else defaultObject[key] = property
})

return defaultObject;
}}
return defaultObject
}
}
Loading

0 comments on commit 4eec884

Please sign in to comment.