diff --git a/package.json b/package.json index 1bbd67d6e..e808a8ded 100644 --- a/package.json +++ b/package.json @@ -82,6 +82,7 @@ "gulp-uglify": "^1.1.0", "hock": "~1.2.0", "istanbul": "*", + "js2xmlparser": "^1.0.0", "mocha": "*", "nock": "^2.6.0", "node-sass": "^3.0.0-alpha.0", diff --git a/src/test/apptask-test.js b/src/test/apptask-test.js index 8fe7a63c5..986e5b600 100644 --- a/src/test/apptask-test.js +++ b/src/test/apptask-test.js @@ -14,6 +14,9 @@ var addons = require('../addons.js'), database = require('../database.js'), expect = require('expect.js'), fs = require('fs'), + hock = require('hock'), + http = require('http'), + js2xml = require('js2xmlparser'), net = require('net'), nock = require('nock'), paths = require('../paths.js'), @@ -62,6 +65,21 @@ var APP = { dnsRecordId: 'someDnsRecordId' }; + var awsHostedZones = { + HostedZones: [{ + Id: '/hostedzone/ZONEID', + Name: 'localhost.', + CallerReference: '305AFD59-9D73-4502-B020-F4E6F889CB30', + ResourceRecordSetCount: 2, + ChangeInfo: { + Id: '/change/CKRTFJA0ANHXB', + Status: 'INSYNC' + } + }], + IsTruncated: false, + MaxItems: '100' + }; + describe('apptask', function () { before(function (done) { config.set('version', '0.5.0'); @@ -183,17 +201,23 @@ describe('apptask', function () { }); }); - xit('registers subdomain', function (done) { + it('registers subdomain', function (done) { nock.cleanAll(); var scope = nock(config.apiServerOrigin()) .post('/api/v1/boxes/' + config.fqdn() + '/awscredentials?token=APPSTORE_TOKEN') - .reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } }) - .post('/api/v1/subdomains?token=' + config.token(), { records: [ { subdomain: APP.location, type: 'A', value: sysinfo.getIp() } ] }) - .reply(201, { ids: [ APP.dnsRecordId ] }); + .times(2) + .reply(201, { credentials: { AccessKeyId: 'accessKeyId', SecretAccessKey: 'secretAccessKey', SessionToken: 'sessionToken' } }); + + var awsScope = nock(config.aws().endpoint) + .get('/2013-04-01/hostedzone') + .reply(200, js2xml('ListHostedZonesResponse', awsHostedZones, { arrayMap: { HostedZones: 'HostedZone'} })) + .post('/2013-04-01/hostedzone/ZONEID/rrset/') + .reply(200, js2xml('ChangeResourceRecordSetsResponse', { ChangeInfo: { Id: 'RRID', Status: 'INSYNC' } })); apptask._registerSubdomain(APP, function (error) { expect(error).to.be(null); expect(scope.isDone()).to.be.ok(); + expect(awsScope.isDone()).to.be.ok(); done(); }); });