Skip to content

Commit

Permalink
fixes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Feb 23, 2021
1 parent c1ef1b5 commit dcda457
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ describe('add prepackaged rules schema', () => {
expect(message.schema).toEqual({});
});

test('You cannot send in an array of threat that are missing "technique"', () => {
test('You can send in an array of threat that are missing "technique"', () => {
const payload: Omit<AddPrepackagedRulesSchema, 'threat'> & {
threat: Array<Partial<Omit<AddPrepackagedRulesSchema['threat'], 'technique'>>>;
} = {
Expand All @@ -944,10 +944,21 @@ describe('add prepackaged rules schema', () => {
const decoded = addPrepackagedRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "threat,technique"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
const expected: AddPrepackagedRulesSchemaDecoded = {
...getAddPrepackagedRulesSchemaDecodedMock(),
threat: [
{
framework: 'fake',
tactic: {
id: 'fakeId',
name: 'fakeName',
reference: 'fakeRef',
},
},
],
};
expect(message.schema).toEqual(expected);
});

test('You can optionally send in an array of false positives', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ describe('import rules schema', () => {
expect(message.schema).toEqual({});
});

test('You cannot send in an array of threat that are missing "technique"', () => {
test('You can send in an array of threat that are missing "technique"', () => {
const payload: Omit<ImportRulesSchema, 'threat'> & {
threat: Array<Partial<Omit<ImportRulesSchema['threat'], 'technique'>>>;
} = {
Expand All @@ -946,10 +946,21 @@ describe('import rules schema', () => {
const decoded = importRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "threat,technique"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
const expected: ImportRulesSchemaDecoded = {
...getImportRulesSchemaDecodedMock(),
threat: [
{
framework: 'fake',
tactic: {
id: 'fakeId',
name: 'fakeName',
reference: 'fakeRef',
},
},
],
};
expect(message.schema).toEqual(expected);
});

test('You can optionally send in an array of false positives', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ describe('patch_rules_schema', () => {
expect(message.schema).toEqual({});
});

test('threat is invalid when updated with missing technique', () => {
test('threat is valid when updated with missing technique', () => {
const threat: Omit<PatchRulesSchema['threat'], 'technique'> = [
{
framework: 'fake',
Expand All @@ -993,10 +993,8 @@ describe('patch_rules_schema', () => {
const decoded = patchRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "threat,technique"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('validates with timeline_id and timeline_title', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ describe('create rules schema', () => {
expect(message.schema).toEqual({});
});

test('You cannot send in an array of threat that are missing "technique"', () => {
test('You can send in an array of threat that are missing "technique"', () => {
const payload = {
...getCreateRulesSchemaMock(),
threat: [
Expand All @@ -636,10 +636,8 @@ describe('create rules schema', () => {
const decoded = createRulesSchema.decode(payload);
const checked = exactCheck(payload, decoded);
const message = pipe(checked, foldLeftRight);
expect(getPaths(left(message.errors))).toEqual([
'Invalid value "undefined" supplied to "threat,technique"',
]);
expect(message.schema).toEqual({});
expect(getPaths(left(message.errors))).toEqual([]);
expect(message.schema).toEqual(payload);
});

test('You can optionally send in an array of false positives', () => {
Expand Down

0 comments on commit dcda457

Please sign in to comment.