aws-spa
Version:
A no-brainer script to deploy a single page app on AWS
85 lines (81 loc) • 3.26 kB
JavaScript
;
var _awsServices = require("./aws-services");
var _route = require("./route53");
var _testHelper = require("./test-helper");
jest.mock('inquirer', () => {
return {
__esModule: true,
default: {
prompt: jest.fn()
}
};
});
describe('route53', () => {
describe('findHostedZone', () => {
const listHostedZonesMock = jest.spyOn(_awsServices.route53, 'listHostedZones');
afterEach(() => {
listHostedZonesMock.mockReset();
});
it('should search among all hosted zones', async () => {
const matchingHostedZone = {
Name: 'example2.com'
};
listHostedZonesMock.mockReturnValueOnce((0, _testHelper.awsResolve)({
HostedZones: [{
Name: 'example1.com'
}],
NextMarker: 'xxx'
})).mockReturnValueOnce((0, _testHelper.awsResolve)({
HostedZones: [matchingHostedZone]
}));
expect(await (0, _route.findHostedZone)('hello.example2.com')).toBe(matchingHostedZone);
});
it('should should match if hosted zone have a trailing dot', async () => {
const matchingHostedZone = {
Name: 'example.com.'
};
listHostedZonesMock.mockReturnValue((0, _testHelper.awsResolve)({
HostedZones: [matchingHostedZone]
}));
expect(await (0, _route.findHostedZone)('hello.example.com')).toBe(matchingHostedZone);
});
it('should return null if there is no hosted found', async () => {
listHostedZonesMock.mockReturnValue((0, _testHelper.awsResolve)({
HostedZones: [{
Name: 'example2.com.'
}]
}));
expect(await (0, _route.findHostedZone)('hello.example.com')).toEqual(null);
});
});
describe('createHostedZone', () => {
const createHostedZoneMock = jest.spyOn(_awsServices.route53, 'createHostedZone');
afterEach(() => {
createHostedZoneMock.mockReset();
});
it('should create a hosted zone', async () => {
createHostedZoneMock.mockReturnValue((0, _testHelper.awsResolve)({
HostedZone: {}
}));
await (0, _route.createHostedZone)('hello.example.com');
expect(createHostedZoneMock).toHaveBeenCalledTimes(1);
const hostedZoneParams = createHostedZoneMock.mock.calls[0][0];
expect(hostedZoneParams.Name).toEqual('hello.example.com');
});
});
describe('updateRecord', () => {
const changeResourceRecordSetsMock = jest.spyOn(_awsServices.route53, 'changeResourceRecordSets');
afterEach(() => {
changeResourceRecordSetsMock.mockReset();
});
it('should create a hosted zone', async () => {
changeResourceRecordSetsMock.mockReturnValue((0, _testHelper.awsResolve)());
await (0, _route.updateRecord)('zone-id', 'hello.example.com', 'distribution-id.cloudfront.net');
expect(changeResourceRecordSetsMock).toHaveBeenCalledTimes(1);
const updateRecordParams = changeResourceRecordSetsMock.mock.calls[0][0];
expect(updateRecordParams.HostedZoneId).toEqual('zone-id');
expect(updateRecordParams.ChangeBatch.Changes[0].ResourceRecordSet.Name).toEqual('hello.example.com.');
expect(updateRecordParams.ChangeBatch.Changes[0].ResourceRecordSet.AliasTarget.DNSName).toEqual('distribution-id.cloudfront.net.');
});
});
});