|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var Promise = require('ember-cli/lib/ext/promise'); |
| 4 | +var assert = require('ember-cli/tests/helpers/assert'); |
| 5 | + |
| 6 | +var stubProject = { |
| 7 | + name: function(){ |
| 8 | + return 'my-project'; |
| 9 | + } |
| 10 | +}; |
| 11 | + |
| 12 | +describe('s3-index plugin', function() { |
| 13 | + var subject, mockUi; |
| 14 | + |
| 15 | + beforeEach(function() { |
| 16 | + subject = require('../../index'); |
| 17 | + mockUi = { |
| 18 | + verbose: true, |
| 19 | + messages: [], |
| 20 | + write: function() { }, |
| 21 | + writeLine: function(message) { |
| 22 | + this.messages.push(message); |
| 23 | + } |
| 24 | + }; |
| 25 | + }); |
| 26 | + |
| 27 | + it('has a name', function() { |
| 28 | + var result = subject.createDeployPlugin({ |
| 29 | + name: 'test-plugin' |
| 30 | + }); |
| 31 | + |
| 32 | + assert.equal(result.name, 'test-plugin'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('implements the correct hooks', function() { |
| 36 | + var plugin = subject.createDeployPlugin({ |
| 37 | + name: 'test-plugin' |
| 38 | + }); |
| 39 | + assert.ok(plugin.configure); |
| 40 | + assert.ok(plugin.upload); |
| 41 | + assert.ok(plugin.activate); |
| 42 | + assert.ok(plugin.fetchRevisions); |
| 43 | + assert.ok(plugin.fetchInitialRevisions); |
| 44 | + }); |
| 45 | + |
| 46 | + |
| 47 | + describe('fetchInitialRevisions hook', function() { |
| 48 | + it('fills the initialRevisions variable on context', function() { |
| 49 | + var plugin; |
| 50 | + var context; |
| 51 | + |
| 52 | + plugin = subject.createDeployPlugin({ |
| 53 | + name: 's3-index' |
| 54 | + }); |
| 55 | + |
| 56 | + context = { |
| 57 | + ui: mockUi, |
| 58 | + project: stubProject, |
| 59 | + config: { |
| 60 | + 's3-index': { |
| 61 | + prefix: 'test-prefix', |
| 62 | + filePattern: 'index.html', |
| 63 | + bucket: 'my-bucket', |
| 64 | + region: 'my-region', |
| 65 | + s3DeployClient: function(/* context */) { |
| 66 | + return { |
| 67 | + fetchRevisions: function(/* keyPrefix, revisionKey */) { |
| 68 | + return Promise.resolve([{ |
| 69 | + revision: 'a', |
| 70 | + active: false |
| 71 | + }]); |
| 72 | + } |
| 73 | + }; |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + }; |
| 78 | + plugin.beforeHook(context); |
| 79 | + plugin.configure(context); |
| 80 | + |
| 81 | + return assert.isFulfilled(plugin.fetchInitialRevisions(context)) |
| 82 | + .then(function(result) { |
| 83 | + assert.deepEqual(result, { |
| 84 | + initialRevisions: [{ |
| 85 | + "active": false, |
| 86 | + "revision": "a" |
| 87 | + }] |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + describe('fetchRevisions hook', function() { |
| 94 | + it('fills the revisions variable on context', function() { |
| 95 | + var plugin; |
| 96 | + var context; |
| 97 | + |
| 98 | + plugin = subject.createDeployPlugin({ |
| 99 | + name: 's3-index' |
| 100 | + }); |
| 101 | + |
| 102 | + context = { |
| 103 | + ui: mockUi, |
| 104 | + project: stubProject, |
| 105 | + |
| 106 | + config: { |
| 107 | + 's3-index': { |
| 108 | + prefix: 'test-prefix', |
| 109 | + filePattern: 'index.html', |
| 110 | + bucket: 'my-bucket', |
| 111 | + region: 'my-region', |
| 112 | + s3DeployClient: function(/* context */) { |
| 113 | + return { |
| 114 | + fetchRevisions: function(/* keyPrefix, revisionKey */) { |
| 115 | + return Promise.resolve([{ |
| 116 | + revision: 'a', |
| 117 | + active: false |
| 118 | + }]); |
| 119 | + } |
| 120 | + }; |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + }; |
| 125 | + plugin.beforeHook(context); |
| 126 | + plugin.configure(context); |
| 127 | + |
| 128 | + return assert.isFulfilled(plugin.fetchRevisions(context)) |
| 129 | + .then(function(result) { |
| 130 | + assert.deepEqual(result, { |
| 131 | + revisions: [{ |
| 132 | + "active": false, |
| 133 | + "revision": "a" |
| 134 | + }] |
| 135 | + }); |
| 136 | + }); |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments