Skip to content

Commit fcd01fb

Browse files
committed
[BREAKING] add fetchInitialRevisions and move to revisionData key
this implements ember-cli-deploy/ember-cli-deploy#338
1 parent d8d66be commit fcd01fb

File tree

2 files changed

+130
-5
lines changed

2 files changed

+130
-5
lines changed

index.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,33 @@ module.exports = {
128128
}
129129
},
130130

131+
fetchInitialRevisions: function(/* context */) {
132+
var redisDeployClient = this.readConfig('redisDeployClient');
133+
var keyPrefix = this.readConfig('keyPrefix');
134+
this.log('Listing initial revisions for key: `' + keyPrefix + '`', { verbose: true });
135+
return Promise.resolve(redisDeployClient.fetchRevisions(keyPrefix))
136+
.then(function(revisions) {
137+
return {
138+
revisionData: {
139+
initial: revisions
140+
}
141+
};
142+
})
143+
.catch(this._errorMessage.bind(this));
144+
},
145+
131146
fetchRevisions: function(context) {
132147
var redisDeployClient = this.readConfig('redisDeployClient');
133148
var keyPrefix = this.readConfig('keyPrefix');
134149

135150
this.log('Listing revisions for key: `' + keyPrefix + '`');
151+
var data = context.revisionData || {};
136152
return Promise.resolve(redisDeployClient.fetchRevisions(keyPrefix))
137-
.then(function(revisions){
138-
return { revisions: revisions };
153+
.then(function(revisions) {
154+
data.revisions = revisions;
155+
return {
156+
revisionData: data
157+
};
139158
})
140159
.catch(this._errorMessage.bind(this));
141160
},

tests/unit/index-nodetest.js

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,54 @@ describe('redis plugin', function() {
575575
});
576576
});
577577

578+
describe('fetchInitialRevisions hook', function() {
579+
it('fills the revisionsData.initial variable on context', function() {
580+
var plugin;
581+
var context;
582+
583+
plugin = subject.createDeployPlugin({
584+
name: 'redis'
585+
});
586+
587+
context = {
588+
ui: mockUi,
589+
project: stubProject,
590+
config: {
591+
redis: {
592+
keyPrefix: 'test-prefix',
593+
filePattern: 'index.html',
594+
distDir: 'tests',
595+
revisionKey: '123abc',
596+
redisDeployClient: function(context) {
597+
return {
598+
fetchRevisions: function(keyPrefix, revisionKey) {
599+
return Promise.resolve([{
600+
revision: 'a',
601+
active: false
602+
}]);
603+
}
604+
};
605+
}
606+
}
607+
}
608+
};
609+
plugin.beforeHook(context);
610+
plugin.configure(context);
611+
612+
return assert.isFulfilled(plugin.fetchInitialRevisions(context))
613+
.then(function(result) {
614+
assert.deepEqual(result, {
615+
revisionData: {
616+
initial: [{
617+
"active": false,
618+
"revision": "a"
619+
}]
620+
}
621+
});
622+
});
623+
});
624+
});
625+
578626
describe('fetchRevisions hook', function() {
579627
it('fills the revisions variable on context', function() {
580628
var plugin;
@@ -610,14 +658,72 @@ describe('redis plugin', function() {
610658
plugin.configure(context);
611659

612660
return assert.isFulfilled(plugin.fetchRevisions(context))
613-
.then(function(result) {
614-
assert.deepEqual(result, {
661+
.then(function(result) {
662+
assert.deepEqual(result, {
663+
revisionData: {
664+
revisions: [{
665+
"active": false,
666+
"revision": "a"
667+
}]
668+
}
669+
});
670+
});
671+
});
672+
673+
it('merges with the initialData', function() {
674+
var plugin;
675+
var context;
676+
677+
plugin = subject.createDeployPlugin({
678+
name: 'redis'
679+
});
680+
681+
context = {
682+
ui: mockUi,
683+
project: stubProject,
684+
config: {
685+
redis: {
686+
keyPrefix: 'test-prefix',
687+
filePattern: 'index.html',
688+
distDir: 'tests',
689+
revisionKey: '123abc',
690+
redisDeployClient: function(context) {
691+
return {
692+
fetchRevisions: function(keyPrefix, revisionKey) {
693+
return Promise.resolve([{
694+
revision: 'a',
695+
active: false
696+
}]);
697+
}
698+
};
699+
}
700+
}
701+
},
702+
revisionData: {
703+
initial: [{
704+
"active": false,
705+
"revision": "old"
706+
}]
707+
}
708+
};
709+
plugin.beforeHook(context);
710+
plugin.configure(context);
711+
712+
return assert.isFulfilled(plugin.fetchRevisions(context))
713+
.then(function(result) {
714+
assert.deepEqual(result, {
715+
revisionData: {
716+
initial: [{
717+
"active": false,
718+
"revision": "old"
719+
}],
615720
revisions: [{
616721
"active": false,
617722
"revision": "a"
618723
}]
619-
});
724+
}
620725
});
726+
});
621727
});
622728
});
623729
});

0 commit comments

Comments
 (0)