Skip to content

Commit

Permalink
adding additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbonig committed Feb 27, 2020
1 parent b146cdf commit e31ea46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-iam/lib/policy-statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class PolicyStatement {
if (typeof (field) !== "string" && !Array.isArray(field)) {
throw new Error("Fields must be either a string or an array of strings");
}
if (Array.isArray(field) && !field.reduce((acc: boolean, f: any) => (acc && typeof (f) === "string"), true)) {
throw new Error("Fields must be either a string or an array of strings");
}
return Array.isArray(field) ? field : [field];
};

Expand Down
15 changes: 15 additions & 0 deletions packages/@aws-cdk/aws-iam/test/policy-statement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,21 @@ describe('IAM policy statement', () => {
expect(stack.resolve(doc)).toEqual(policyDocument);
});

test('throws error with field data being object', () => {
expect(() => {
PolicyStatement.fromJson({
Action: {}
});
}).toThrow(/Fields must be either a string or an array of strings/);
});

test('throws error with field data being object', () => {
expect(() => {
PolicyStatement.fromJson({
Action: [{}]
});
}).toThrow(/Fields must be either a string or an array of strings/);
});
});

});

0 comments on commit e31ea46

Please sign in to comment.