Skip to content

Commit 628d121

Browse files
committed
Added tests for the new url fix
1 parent 91009ed commit 628d121

5 files changed

Lines changed: 50 additions & 16 deletions

File tree

lib/experiment.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,18 @@ Experiment.prototype.saveAttributes = function() {
132132
.attributes);
133133
}
134134

135-
Experiment.prototype.getOptcliUrl = function() {
136-
var optcliUrl;
137-
var appendToUrl;
138-
optcliUrl = this.attributes.edit_url;
139-
optcliUrl.indexOf('?') === -1 ?
140-
appendToUrl = '?optcli=activate' :
141-
appendToUrl = '&optcli=activate';
142-
optcliUrl.indexOf('#') === -1 ?
143-
optcliUrl += appendToUrl :
144-
optcliUrl = optcliUrl.replace('#', appendToUrl + '#');
145-
146-
return optcliUrl;
135+
Experiment.prototype.getOptcliURL = function() {
136+
var optcliURL;
137+
var appendToURL;
138+
optcliURL = this.attributes.edit_url;
139+
optcliURL.indexOf('?') === -1 ?
140+
appendToURL = '?optcli=activate' :
141+
appendToURL = '&optcli=activate';
142+
optcliURL.indexOf('#') === -1 ?
143+
optcliURL += appendToURL :
144+
optcliURL = optcliURL.replace('#', appendToURL + '#');
145+
146+
return optcliURL;
147147
}
148148

149149
module.exports = Experiment;

lib/server/controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function LocalController(variation, port) {
3636

3737
this.locals = {
3838
_port: this.port,
39-
edit_url: this.experiment.getOptcliUrl(),
39+
edit_url: this.experiment.getOptcliURL(),
4040
experiment_desc: this.experiment.attributes.description,
4141
variation_desc: this.variation.attributes.description
4242
}

test/commands/push-variation.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var directory = {};
2222

2323
var pushVariation = proxyquire('../../lib/commands/push-variation', { 'optimizely-node-client': ClientStub });
2424

25-
describe('Push Experiment Module', function() {
25+
describe('Push Variation Module', function() {
2626
before(function(done) {
2727
//Create temporary project directory and enter it
2828
quickTemp.makeOrRemake(directory, 'project');

test/experiment.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('Experiment Object', function (){
5858
});
5959
});
6060
after(function(done){
61-
quickTemp.remove(directories, 'experiment');
61+
quickTemp.remove(directories, 'project');
6262
done();
6363
})
6464
describe('#create()', function() {
@@ -204,4 +204,38 @@ describe('Experiment Object', function (){
204204
expect(functionCalls[0][0]).to.deep.equal(expArgs);
205205
});
206206
});
207+
describe('#getOptcliURL()', function(){
208+
it('Should put it at the end with an &', function(){
209+
var newURL = edit_url + '?myparam=true';
210+
var experiment = new Experiment({
211+
description: description,
212+
edit_url: newURL
213+
}, experimentPath+'1');
214+
expect(experiment.getOptcliURL()).to.equal(newURL+'&optcli=activate');
215+
});
216+
it('Should put it at the end with a ?', function(){
217+
var newURL = edit_url;
218+
var experiment = new Experiment({
219+
description: description,
220+
edit_url: newURL
221+
}, experimentPath+'1');
222+
expect(experiment.getOptcliURL()).to.equal(newURL+'?optcli=activate');
223+
});
224+
it('Should put it before the hash with an &', function(){
225+
var newURL = edit_url + '?mygetparam=true#myhashparam=true';
226+
var experiment = new Experiment({
227+
description: description,
228+
edit_url: newURL
229+
}, experimentPath+'1');
230+
expect(experiment.getOptcliURL()).to.equal(newURL.replace('#','&optcli=activate#'));
231+
});
232+
it('Should put it before the hash with a ?', function(){
233+
var newURL = edit_url + '#myhashparam=true';
234+
var experiment = new Experiment({
235+
description: description,
236+
edit_url: newURL
237+
}, experimentPath+'1');
238+
expect(experiment.getOptcliURL()).to.equal(newURL.replace('#','?optcli=activate#'));
239+
});
240+
});
207241
});

test/mocha.opts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
--recursive

0 commit comments

Comments
 (0)