UNPKG

aws-spa

Version:

A no-brainer script to deploy a single page app on AWS

52 lines (47 loc) 1.9 kB
"use strict"; var _awsServices = require("./aws-services"); var _iam = require("./iam"); var _testHelper = require("./test-helper"); describe('IAM', () => { const getRole = jest.spyOn(_awsServices.iam, 'getRole'); const createRole = jest.spyOn(_awsServices.iam, 'createRole'); const attachRolePolicy = jest.spyOn(_awsServices.iam, 'attachRolePolicy'); beforeEach(() => { getRole.mockReset(); createRole.mockReset(); attachRolePolicy.mockReset(); }); describe('getRoleARNForBasicLambdaExectution', () => { it('should return the role ARN if role is found', async () => { getRole.mockReturnValueOnce((0, _testHelper.awsResolve)({ Role: { Arn: 'some-ARN' } })); expect(await (0, _iam.getRoleARNForBasicLambdaExectution)('some-role')).toEqual('some-ARN'); }); it('should throw if error is not 404', async () => { expect.assertions(1); getRole.mockReturnValueOnce((0, _testHelper.awsReject)(400, 'some message')); try { await (0, _iam.getRoleARNForBasicLambdaExectution)('some-role'); } catch (error) { expect(error.message).toEqual('some message'); } }); it('should create the role if role is not found', async () => { getRole.mockReturnValueOnce((0, _testHelper.awsReject)(404)); createRole.mockReturnValueOnce((0, _testHelper.awsResolve)({ Role: { Arn: 'new-arn' } })); attachRolePolicy.mockReturnValueOnce((0, _testHelper.awsResolve)()); expect(await (0, _iam.getRoleARNForBasicLambdaExectution)('some-role', 0)).toEqual('new-arn'); expect(createRole).toHaveBeenCalledTimes(1); expect(createRole.mock.calls[0][0].RoleName).toEqual('some-role'); expect(attachRolePolicy).toHaveBeenCalledTimes(1); expect(attachRolePolicy.mock.calls[0][0].RoleName).toEqual('some-role'); }); }); });