forked from OpenCTI-Platform/opencti
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[backend/frontend] Invalidate empty CSV mappers (OpenCTI-Platform#4644)
- Loading branch information
Showing
5 changed files
with
68 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
opencti-platform/opencti-graphql/tests/01-unit/domain/csv-mapper-utils-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { assert, describe, expect, it } from 'vitest'; | ||
import { csvMapperMockSimpleDifferentEntities } from '../../data/csv-mapper-mock-simple-different-entities'; | ||
import { validate } from '../../../src/modules/internal/csvMapper/csvMapper-utils'; | ||
import { testContext } from '../../utils/testQuery'; | ||
import type { BasicStoreEntityCsvMapper } from '../../../src/modules/internal/csvMapper/csvMapper-types'; | ||
|
||
describe('CSV Mapper', () => { | ||
it('validate a valid mapper', async () => { | ||
await validate(testContext, { | ||
...csvMapperMockSimpleDifferentEntities as BasicStoreEntityCsvMapper, | ||
name: 'Valid Mapper' | ||
}); | ||
assert(true); | ||
}); | ||
it('invalidate a invalid mapper', async () => { | ||
const mapper = csvMapperMockSimpleDifferentEntities as BasicStoreEntityCsvMapper; | ||
await expect(() => validate(testContext, { | ||
...mapper, | ||
name: 'Invalid Mapper', | ||
representations: [], // cannot have 0 representations | ||
})).rejects.toThrowError('CSV Mapper \'Invalid Mapper\' has no representation'); | ||
|
||
await expect(() => validate(testContext, { | ||
...mapper, | ||
name: 'Invalid Mapper', | ||
representations: [ | ||
{ | ||
...mapper.representations[0], | ||
attributes: [], // missing attribute | ||
}, | ||
mapper.representations[1], | ||
] | ||
})).rejects.toThrowError(/missing values for required attribute : name/); | ||
|
||
// TODO: cover more validation tests | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters