Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
feat: remove reference to experiments and main bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
foxted committed Dec 15, 2019
1 parent b91ca13 commit 8be9f48
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 139 deletions.
250 changes: 136 additions & 114 deletions src/__tests__/mocks/variate.json
Original file line number Diff line number Diff line change
@@ -1,136 +1,158 @@
{
"live": {
"experiments": [
{
"id": 16,
"name": "Homepage - Hero Banner",
"status": "live",
"targeting": {
"views": {
"include": [
"/$"
],
"exclude": []
},
"audiences": {
"and": [
{
"==": [
{
"var": "country"
},
"Canada"
]
},
{
"==": [
{
"var": "state"
},
"BC"
]
}
]
}
"experiments": {
"nM3ntXmMj2dX86xnrvVK": {
"id": "nM3ntXmMj2dX86xnrvVK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"name": "Homepage - Hero Banner",
"environment": "production",
"manualPageview": false,
"targeting": {
"views": {
"include": [
"/$"
],
"exclude": []
},
"variations": [
{
"id": 22,
"trafficAllocation": {
"max": 100,
"min": 0
"segments": {
"and": [
{
"==": [
{
"var": "country"
},
"Canada"
]
},
"components": {
"Hero": {
"id": 25,
"variables": {
"backgroundImage": "https://placeimg.com/1000/500/animals"
}
}
{
"==": [
{
"var": "state"
},
"BC"
]
}
]
}
},
"variations": {
"GhPz7J72ABIQvOqdTtnm": {
"id": "GhPz7J72ABIQvOqdTtnm",
"experimentId": "nM3ntXmMj2dX86xnrvVK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"trafficAllocation": {
"max": 50,
"min": 0
},
{
"id": 23,
"trafficAllocation": {
"max": 100,
"min": 51
},
"components": {
"Hero": {
"id": 25,
"variables": {
"backgroundImage": "https://placeimg.com/1000/500/arch"
}
"components": {
"Hero": {
"id": "PjaBNzyQYP2W8zESoELs",
"variationId": "GhPz7J72ABIQvOqdTtnm",
"experimentId": "nM3ntXmMj2dX86xnrvVK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"variables": {
"backgroundImage": "https://placeimg.com/1000/500/animals"
}
}
}
]
},
{
"id": 17,
"name": "Homepage - Hero Headline",
"status": "draft",
"targeting": {
"views": {
"include": [
"/$"
],
"exclude": []
},
"RyQqWxnWqumQ7WpjvLr6": {
"id": "RyQqWxnWqumQ7WpjvLr6",
"experimentId": "nM3ntXmMj2dX86xnrvVK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"trafficAllocation": {
"max": 100,
"min": 51
},
"audiences": {
"and": [
{
"==": [
{
"var": "country"
},
"France"
]
},
{
"==": [
{
"var": "state"
},
"BC"
]
"components": {
"Hero": {
"id": "PjaBNzyQYP2W8zESoELs",
"variationId": "RyQqWxnWqumQ7WpjvLr6",
"experimentId": "nM3ntXmMj2dX86xnrvVK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"variables": {
"backgroundImage": "https://placeimg.com/1000/500/arch"
}
]
}
}
}
}
},
"C74lbTFFVUk6Zj76ysMK": {
"id": "C74lbTFFVUk6Zj76ysMK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"name": "Homepage - Hero Headline",
"environment": "development",
"manualPageview": true,
"targeting": {
"views": {
"include": [
"/$"
],
"exclude": []
},
"variations": [
{
"id": 24,
"trafficAllocation": {
"max": 50,
"min": 0
"segments": {
"and": [
{
"==": [
{
"var": "country"
},
"France"
]
},
"components": {
"Hero": {
"id": 25,
"variables": {
"headline": "Awesome control variation!"
}
{
"==": [
{
"var": "state"
},
"BC"
]
}
]
}
},
"variations": {
"HmXushDwr8vroLEIYGdc": {
"id": "HmXushDwr8vroLEIYGdc",
"experimentId": "C74lbTFFVUk6Zj76ysMK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"trafficAllocation": {
"max": 50,
"min": 0
},
"components": {
"Hero": {
"id": "PjaBNzyQYP2W8zESoELs",
"variationId": "HmXushDwr8vroLEIYGdc",
"experimentId": "C74lbTFFVUk6Zj76ysMK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"variables": {
"headline": "Awesome control variation!"
}
}
}
},
"RHImVSAalXTbKoNtYdGM": {
"id": "RHImVSAalXTbKoNtYdGM",
"experimentId": "C74lbTFFVUk6Zj76ysMK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"trafficAllocation": {
"max": 100,
"min": 51
},
{
"id": 25,
"trafficAllocation": {
"max": 100,
"min": 51
},
"components": {
"Hero": {
"id": 25,
"variables": {
"headline": "Awesome variation 1!"
}
"components": {
"Hero": {
"id": "PjaBNzyQYP2W8zESoELs",
"variationId": "RHImVSAalXTbKoNtYdGM",
"experimentId": "C74lbTFFVUk6Zj76ysMK",
"siteId": "djGYAl2Dx0JDGuAm5mph",
"variables": {
"headline": "Awesome variation 1!"
}
}
}
]
}
}
]
}
}
}
20 changes: 5 additions & 15 deletions src/__tests__/variate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ const tests = () => {
const computedProperties = vm.$options.computed;
expect(computedProperties.variateComponentName).toBeDefined();
expect(vm.variateComponentName).toBe('App');
expect(computedProperties.variateMainBucket).toBeDefined();
expect(typeof vm.variateMainBucket).toBe('number');
expect(computedProperties.variateComponent).toBeDefined();
expect(typeof vm.variateComponent).toBe('object');
expect(computedProperties.variateBucket).toBeDefined();
expect(typeof vm.variateBucket).toBe('number');
expect(computedProperties.variateExperiments).toBeDefined();
expect(Array.isArray(vm.variateExperiments)).toBeTruthy();
expect(computedProperties.variateVariables).toBeDefined();
expect(typeof vm.variateVariables).toBe('object');
});
Expand All @@ -41,14 +37,10 @@ const tests = () => {
const computedProperties = vm.$options.computed;
expect(computedProperties.variateComponentName).toBeDefined();
expect(vm.variateComponentName).toBe('Hero');
expect(computedProperties.variateMainBucket).toBeDefined();
expect(typeof vm.variateMainBucket).toBe('number');
expect(computedProperties.variateComponent).toBeDefined();
expect(typeof vm.variateComponent).toBe('object');
expect(computedProperties.variateBucket).toBeDefined();
expect(typeof vm.variateBucket).toBe('number');
expect(computedProperties.variateExperiments).toBeDefined();
expect(Array.isArray(vm.variateExperiments)).toBeTruthy();
expect(computedProperties.variateVariables).toBeDefined();
expect(typeof vm.variateVariables).toBe('object');
});
Expand Down Expand Up @@ -78,7 +70,7 @@ const tests = () => {
expect(vm.$variate.env.targeting.state).toBeDefined();
expect(vm.$variate.env.targeting.state).toBe('BC');
});
it('It can get the component experiments and variable if Variate is initialized', () => {
it('It can get the component information if Variate is initialized', () => {
const vm = new Vue({
variateId: 'Hero',
render() {
Expand All @@ -104,12 +96,10 @@ const tests = () => {
expect(vm.$options.computed.variateComponent.call(vm).id).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).variables).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).variables.backgroundImage).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments[0]).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments[0].experiment).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments[0].variation).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments[0].bucket).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experiments[0].variables).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).bucket).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).variationId).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).experimentId).toBeDefined();
expect(vm.$options.computed.variateComponent.call(vm).siteId).toBeDefined();
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/lang/debug.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Components
export const LOAD_COMPONENT= `[COMPONENT] %s`;
export const LOAD_COMPONENT_EXPERIMENTS = `Running experiments:`;
export const VIEW_EXPERIMENT = 'View experiment: %s';
15 changes: 6 additions & 9 deletions src/variate.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export function install(Vue, options) {
if(this.$options.variateId) return this.$options.variateId;
return this.variateId || this.$options._componentTag;
},
variateMainBucket() {
return this.$variate.getMainTrafficBucket();
},
variateComponent() {
if (typeof this.$variate.components[this.variateComponentName] !== 'undefined') {
return this.$variate.components[this.variateComponentName];
Expand All @@ -30,18 +27,18 @@ export function install(Vue, options) {
variateBucket() {
return this.variateComponent.bucket || 0;
},
variateExperiments() {
return this.variateComponent.experiments || [];
},
variateVariables() {
return this.variateComponent.variables || {};
},
},
created() {
if (Object.keys(this.variateComponent).length > 0 && typeof this.variateExperiments !== 'undefined') {
if (Object.keys(this.variateComponent).length > 0) {
options.debug && console.groupCollapsed(debug.LOAD_COMPONENT, this.variateComponentName);
options.debug && console.log(debug.LOAD_COMPONENT_EXPERIMENTS);
options.debug && console.log(this.variateExperiments);
options.debug && console.log(
debug.VIEW_EXPERIMENT,
`https://variate.ca/sites/${this.variateComponent.siteId}/experiments/${this.variateComponent.experimentId}`
);
options.debug && console.log(this.variateComponent);
options.debug && console.groupEnd();
}
},
Expand Down

0 comments on commit 8be9f48

Please sign in to comment.