UNPKG

briareus

Version:

Briareus assists with Feature Branch deploys to ECS

76 lines (63 loc) 2.17 kB
'use strict' const expect = require('expect.js'); const AWS = require('aws-sdk-mock'); const helpers = require('../../helpers'); const CreateAcmCertificate = require('../../../lib/service/actions/create-acm-certificate'); describe('Action:CreateAcmCertificate', function () { afterEach(helpers.afterEach); it('should create an ACM certificate', function (done) { this.timeout(12000); let certificateArn = 'arn:acm:1' let describeCertificateCalls = 0; let payload = { name: 'briareus-variant', slug: 'my-branch', hashedSlug: 'hashbang', image: 'app:123', endpoint: { host: 'branch.bugcrowd.engineering' } }; let validationOptions = [{ DomainName: payload.endpoint.host, ResourceRecord: {} }]; AWS.mock('ACM', 'requestCertificate', function (params, cb) { expect(params.DomainName).to.equal(payload.endpoint.host); expect(params.IdempotencyToken).equal(payload.hashedSlug); expect(params.SubjectAlternativeNames[0]).to.equal(`*.${payload.endpoint.host}`); expect(params.Tags[0].Value.length).greaterThan(0); cb(null, { CertificateArn: certificateArn }); }); AWS.mock('ACM', 'describeCertificate', function (params, cb) { expect(params.CertificateArn).to.equal(certificateArn); describeCertificateCalls++; if (describeCertificateCalls === 1) { // First call; provide an empty list return cb(null, { Certificate: { CertificateArn: certificateArn } }); }; if (describeCertificateCalls === 2) { return cb(null, { Certificate: { CertificateArn: certificateArn, DomainValidationOptions: validationOptions } }); }; throw Error('should not get here'); }); CreateAcmCertificate({}, payload, (err, patches) => { expect(err).to.equal(null); expect(patches[0]).to.eql({ op: 'add', path: '/assets/acmCertificate', value: { arn: certificateArn, validationOptions: validationOptions } }); done(); }) }); });