Skip to content

Commit

Permalink
Merge branch 'develop' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Rassokhin authored and Stanislav Rassokhin committed Sep 13, 2023
2 parents 026db44 + 4d4909b commit eede634
Show file tree
Hide file tree
Showing 2 changed files with 14,769 additions and 18,338 deletions.
42 changes: 33 additions & 9 deletions common/converter/array.unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,44 @@ test('can return items', () => {
})
})

test('can detect missing property', () => {
test('can detect missing property', async () => {
const source = [
{ a: 'hello', b: '95' },
{ a: 'there' }
]
const converter = new ArrayConverter(source)
converter.convert('a').toString()
converter.convert('b').toInt()
expect.assertions(1)
return converter.validate().catch(e => expect(e).toBeInstanceOf(ValidationError))
expect.assertions(2)
let err
try {
await converter.validate()
} catch (e) {
err = e
} finally {
expect(err).toBeInstanceOf(ValidationError)
expect(err.message).toBe('Validation errors: Parameter \'b\' the parameter is required but was not provided.')
}
})

test('can detect incorrect type (int)', () => {
test('can detect incorrect type (int)', async () => {
const source = [
{ a: 'hello', b: '95' },
{ a: 'there', b: 'not an int' }
]
const converter = new ArrayConverter(source)
converter.convert('a').toString()
converter.convert('b').toInt()
expect.assertions(1)
return converter.validate().catch(e => expect(e).toBeInstanceOf(ValidationError))
expect.assertions(2)
let err
try {
await converter.validate()
} catch (e) {
err = e
} finally {
expect(err).toBeInstanceOf(ValidationError)
expect(err.message).toBe('Validation errors: Parameter \'b\' should be an integer.')
}
})

test('can convert string to int', () => {
Expand All @@ -61,7 +77,7 @@ test('can convert string to int', () => {
})
})

test('can detect multiple type errors', () => {
test('can detect multiple type errors', async () => {
const source = [
{ a: 'hello', b: '95' },
{ a: 'there', b: 'not an int' },
Expand All @@ -70,8 +86,16 @@ test('can detect multiple type errors', () => {
const converter = new ArrayConverter(source)
converter.convert('a').toString()
converter.convert('b').toInt()
expect.assertions(1)
return converter.validate().catch(e => expect(e).toBeInstanceOf(ValidationError))
expect.assertions(2)
let err
try {
await converter.validate()
} catch (e) {
err = e
} finally {
expect(err).toBeInstanceOf(ValidationError)
expect(err.message).toBe('Validation errors: Parameter \'b\' should be an integer.')
}
})

test('can camelize', () => {
Expand Down
Loading

0 comments on commit eede634

Please sign in to comment.