2021-09-30 11:44:30 +02:00
|
|
|
/// <reference types="cypress" />
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
import { disableFeatureStrategiesProductionGuard } from '../../../src/component/feature/FeatureView/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard';
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
const randomId = String(Math.random()).split('.')[1];
|
|
|
|
const featureToggleName = `unleash-e2e-${randomId}`;
|
|
|
|
const enterprise = Boolean(Cypress.env('ENTERPRISE'));
|
|
|
|
const passwordAuth = Cypress.env('PASSWORD_AUTH');
|
|
|
|
const authToken = Cypress.env('AUTH_TOKEN');
|
|
|
|
const baseUrl = Cypress.config().baseUrl;
|
|
|
|
let strategyId = '';
|
2021-09-30 11:44:30 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
describe('feature', () => {
|
2021-09-30 11:44:30 +02:00
|
|
|
after(() => {
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
url: `${baseUrl}/api/admin/features/${featureToggleName}`,
|
|
|
|
headers: { Authorization: authToken },
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
cy.request({
|
|
|
|
method: 'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
url: `${baseUrl}/api/admin/archive/${featureToggleName}`,
|
|
|
|
headers: { Authorization: authToken },
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-02-25 10:21:28 +01:00
|
|
|
disableFeatureStrategiesProductionGuard();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.visit('/');
|
|
|
|
|
|
|
|
if (passwordAuth) {
|
|
|
|
cy.get('[data-test="LOGIN_EMAIL_ID"]').type('test@test.com');
|
|
|
|
cy.get('[data-test="LOGIN_PASSWORD_ID"]').type('qY70$NDcJNXA');
|
|
|
|
cy.get("[data-test='LOGIN_BUTTON']").click();
|
|
|
|
} else {
|
|
|
|
cy.get('[data-test=LOGIN_EMAIL_ID]').type('test@unleash-e2e.com');
|
|
|
|
cy.get('[data-test=LOGIN_BUTTON]').click();
|
|
|
|
}
|
2022-02-25 10:21:28 +01:00
|
|
|
|
|
|
|
// Wait for the login redirects to complete.
|
|
|
|
cy.get('[data-test=HEADER_USER_AVATAR');
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can create a feature toggle', () => {
|
|
|
|
if (document.querySelector("[data-test='CLOSE_SPLASH']")) {
|
2021-11-26 11:12:37 +01:00
|
|
|
cy.get("[data-test='CLOSE_SPLASH']").click();
|
|
|
|
}
|
|
|
|
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get('[data-test=NAVIGATE_TO_CREATE_FEATURE').click();
|
|
|
|
|
2021-11-26 16:07:05 +01:00
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
|
|
|
cy.get("[data-test='CF_NAME_ID'").type(featureToggleName);
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get("[data-test='CF_DESC_ID'").type('hello-world');
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get("[data-test='CF_CREATE_BTN_ID']").click();
|
|
|
|
cy.wait('@createFeature');
|
|
|
|
cy.url().should('include', featureToggleName);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('gives an error if a toggle exists with the same name', () => {
|
2022-02-11 00:43:23 +01:00
|
|
|
cy.get('[data-test=NAVIGATE_TO_CREATE_FEATURE').click();
|
|
|
|
|
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get("[data-test='CF_NAME_ID'").type(featureToggleName);
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get("[data-test='CF_DESC_ID'").type('hello-world');
|
2022-02-11 00:43:23 +01:00
|
|
|
cy.get("[data-test='CF_CREATE_BTN_ID']").click();
|
|
|
|
cy.get("[data-test='INPUT_ERROR_TEXT']").contains(
|
|
|
|
'A feature with this name already exists'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('gives an error if a toggle name is url unsafe', () => {
|
2022-02-11 00:43:23 +01:00
|
|
|
cy.get('[data-test=NAVIGATE_TO_CREATE_FEATURE').click();
|
|
|
|
|
|
|
|
cy.intercept('POST', '/api/admin/projects/default/features').as(
|
|
|
|
'createFeature'
|
|
|
|
);
|
|
|
|
|
|
|
|
cy.get("[data-test='CF_NAME_ID'").type('featureToggleUnsafe####$#//');
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get("[data-test='CF_DESC_ID'").type('hello-world');
|
2022-02-11 00:43:23 +01:00
|
|
|
cy.get("[data-test='CF_CREATE_BTN_ID']").click();
|
|
|
|
cy.get("[data-test='INPUT_ERROR_TEXT']").contains(
|
|
|
|
`"name" must be URL friendly`
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can add a gradual rollout strategy to the development environment', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/strategies`);
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_ID]').click();
|
2021-11-12 11:47:19 +01:00
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_CARD_BUTTON_ID-2').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get('[data-test=ROLLOUT_SLIDER_ID')
|
|
|
|
.click()
|
|
|
|
.type('{leftarrow}'.repeat(20));
|
|
|
|
|
|
|
|
if (enterprise) {
|
|
|
|
cy.get('[data-test=ADD_CONSTRAINT_ID]').click();
|
|
|
|
cy.get('[data-test=CONSTRAINT_AUTOCOMPLETE_ID]')
|
|
|
|
.type('{downArrow}'.repeat(1))
|
|
|
|
.type('{enter}');
|
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'POST',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body.name).to.equal('flexibleRollout');
|
|
|
|
expect(req.body.parameters.groupId).to.equal(featureToggleName);
|
|
|
|
expect(req.body.parameters.stickiness).to.equal('default');
|
|
|
|
expect(req.body.parameters.rollout).to.equal(30);
|
|
|
|
|
|
|
|
if (enterprise) {
|
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
strategyId = res.body.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('addStrategyToFeature');
|
|
|
|
|
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_SAVE_ID]').first().click();
|
|
|
|
cy.wait('@addStrategyToFeature');
|
|
|
|
});
|
|
|
|
|
2022-01-27 17:31:44 +01:00
|
|
|
it('can update a strategy in the development environment', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/strategies`);
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get('[data-test=STRATEGY_ACCORDION_ID-flexibleRollout').click();
|
|
|
|
|
|
|
|
cy.get('[data-test=ROLLOUT_SLIDER_ID')
|
|
|
|
.first()
|
|
|
|
.click()
|
|
|
|
.type('{rightArrow}'.repeat(10));
|
|
|
|
|
|
|
|
cy.get('[data-test=FLEXIBLE_STRATEGY_STICKINESS_ID]')
|
|
|
|
.first()
|
|
|
|
.click()
|
|
|
|
.get('[data-test=SELECT_ITEM_ID-sessionId')
|
|
|
|
.first()
|
|
|
|
.click();
|
|
|
|
|
|
|
|
cy.get('[data-test=FLEXIBLE_STRATEGY_GROUP_ID]')
|
|
|
|
.first()
|
|
|
|
.clear()
|
|
|
|
.type('new-group-id');
|
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'PUT',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies/${strategyId}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
2022-02-25 10:21:28 +01:00
|
|
|
expect(req.body.parameters.groupId).to.equal('new-group-id');
|
2021-09-30 11:44:30 +02:00
|
|
|
expect(req.body.parameters.stickiness).to.equal('sessionId');
|
|
|
|
expect(req.body.parameters.rollout).to.equal(60);
|
|
|
|
|
|
|
|
if (enterprise) {
|
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('updateStrategy');
|
|
|
|
|
|
|
|
cy.get('[data-test=UPDATE_STRATEGY_BUTTON_ID]').first().click();
|
|
|
|
cy.wait('@updateStrategy');
|
|
|
|
});
|
|
|
|
|
2022-01-27 17:31:44 +01:00
|
|
|
it('can delete a strategy in the development environment', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/strategies`);
|
2021-09-30 11:44:30 +02:00
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'DELETE',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies/${strategyId}`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
req.continue(res => {
|
|
|
|
expect(res.statusCode).to.equal(200);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('deleteStrategy');
|
|
|
|
|
|
|
|
cy.get('[data-test=DELETE_STRATEGY_ID-flexibleRollout]').click();
|
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
|
|
|
cy.wait('@deleteStrategy');
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can add a userid strategy to the development environment', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/strategies`);
|
2021-09-30 11:44:30 +02:00
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_ID]').click();
|
2021-11-12 11:47:19 +01:00
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_CARD_BUTTON_ID-3').click();
|
2021-09-30 11:44:30 +02:00
|
|
|
|
|
|
|
if (enterprise) {
|
|
|
|
cy.get('[data-test=ADD_CONSTRAINT_ID]').click();
|
|
|
|
cy.get('[data-test=CONSTRAINT_AUTOCOMPLETE_ID]')
|
|
|
|
.type('{downArrow}'.repeat(1))
|
|
|
|
.type('{enter}');
|
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.get('[data-test=STRATEGY_INPUT_LIST]')
|
|
|
|
.type('user1')
|
|
|
|
.type('{enter}')
|
|
|
|
.type('user2')
|
|
|
|
.type('{enter}');
|
|
|
|
cy.get('[data-test=ADD_TO_STRATEGY_INPUT_LIST]').click();
|
|
|
|
|
|
|
|
cy.intercept(
|
|
|
|
'POST',
|
2022-02-25 10:21:28 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/environments/*/strategies`,
|
2021-09-30 11:44:30 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body.name).to.equal('userWithId');
|
|
|
|
|
|
|
|
expect(req.body.parameters.userIds.length).to.equal(11);
|
|
|
|
|
|
|
|
if (enterprise) {
|
|
|
|
expect(req.body.constraints.length).to.equal(1);
|
|
|
|
} else {
|
|
|
|
expect(req.body.constraints.length).to.equal(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
req.continue(res => {
|
|
|
|
strategyId = res.body.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
).as('addStrategyToFeature');
|
|
|
|
|
|
|
|
cy.get('[data-test=ADD_NEW_STRATEGY_SAVE_ID]').first().click();
|
|
|
|
cy.wait('@addStrategyToFeature');
|
|
|
|
});
|
2021-10-08 11:23:29 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can add two variant to the feature', () => {
|
2021-10-08 11:23:29 +02:00
|
|
|
const variantName = 'my-new-variant';
|
|
|
|
const secondVariantName = 'my-second-variant';
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
|
|
|
if (req.body.length === 1) {
|
|
|
|
expect(req.body[0].op).to.equal('add');
|
2021-11-25 14:05:44 +01:00
|
|
|
expect(req.body[0].path).to.match(/\//);
|
2021-10-08 11:23:29 +02:00
|
|
|
expect(req.body[0].value.name).to.equal(variantName);
|
|
|
|
} else if (req.body.length === 2) {
|
|
|
|
expect(req.body[0].op).to.equal('replace');
|
|
|
|
expect(req.body[0].path).to.match(/weight/);
|
|
|
|
expect(req.body[0].value).to.equal(500);
|
|
|
|
expect(req.body[1].op).to.equal('add');
|
2021-11-25 14:05:44 +01:00
|
|
|
expect(req.body[1].path).to.match(/\//);
|
2021-10-08 11:23:29 +02:00
|
|
|
expect(req.body[1].value.name).to.equal(secondVariantName);
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 10:21:28 +01:00
|
|
|
).as('variantCreation');
|
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=ADD_VARIANT_BUTTON]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get('[data-test=VARIANT_NAME_INPUT]').click().type(variantName);
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantCreation');
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=ADD_VARIANT_BUTTON]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get('[data-test=VARIANT_NAME_INPUT]')
|
|
|
|
.click()
|
|
|
|
.type(secondVariantName);
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantCreation');
|
2021-10-08 11:23:29 +02:00
|
|
|
});
|
2021-10-28 13:32:29 +02:00
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can set weight to fixed value for one of the variants', () => {
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=VARIANT_EDIT_BUTTON]').first().click();
|
|
|
|
cy.get('[data-test=VARIANT_NAME_INPUT]')
|
|
|
|
.children()
|
|
|
|
.find('input')
|
|
|
|
.should('have.attr', 'disabled');
|
|
|
|
cy.get('[data-test=VARIANT_WEIGHT_TYPE]')
|
|
|
|
.children()
|
|
|
|
.find('input')
|
|
|
|
.check();
|
|
|
|
cy.get('[data-test=VARIANT_WEIGHT_INPUT]').clear().type('15');
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
|
|
|
expect(req.body[0].op).to.equal('replace');
|
|
|
|
expect(req.body[0].path).to.match(/weight/);
|
|
|
|
expect(req.body[0].value).to.equal(850);
|
|
|
|
expect(req.body[1].op).to.equal('replace');
|
|
|
|
expect(req.body[1].path).to.match(/weightType/);
|
|
|
|
expect(req.body[1].value).to.equal('fix');
|
|
|
|
expect(req.body[2].op).to.equal('replace');
|
|
|
|
expect(req.body[2].path).to.match(/weight/);
|
|
|
|
expect(req.body[2].value).to.equal(150);
|
|
|
|
}
|
2022-02-25 10:21:28 +01:00
|
|
|
).as('variantUpdate');
|
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.wait('@variantUpdate');
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=VARIANT_WEIGHT]')
|
|
|
|
.first()
|
|
|
|
.should('have.text', '15 %');
|
|
|
|
});
|
|
|
|
|
2022-02-25 10:21:28 +01:00
|
|
|
it('can delete variant', () => {
|
2021-10-08 11:23:29 +02:00
|
|
|
const variantName = 'to-be-deleted';
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2022-02-04 10:36:08 +01:00
|
|
|
cy.visit(`/projects/default/features/${featureToggleName}/variants`);
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=ADD_VARIANT_BUTTON]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
cy.get('[data-test=VARIANT_NAME_INPUT]').click().type(variantName);
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.intercept(
|
|
|
|
'PATCH',
|
2021-11-25 14:05:44 +01:00
|
|
|
`/api/admin/projects/default/features/${featureToggleName}/variants`,
|
2021-10-08 11:23:29 +02:00
|
|
|
req => {
|
|
|
|
const e = req.body.find(e => e.op === 'remove');
|
2021-11-25 14:05:44 +01:00
|
|
|
expect(e.path).to.match(/\//);
|
2021-10-08 11:23:29 +02:00
|
|
|
}
|
|
|
|
).as('delete');
|
2022-02-25 10:21:28 +01:00
|
|
|
|
2021-10-08 11:23:29 +02:00
|
|
|
cy.get(`[data-test=VARIANT_DELETE_BUTTON_${variantName}]`).click();
|
|
|
|
cy.get('[data-test=DIALOGUE_CONFIRM_ID]').click();
|
|
|
|
cy.wait('@delete');
|
|
|
|
});
|
2021-09-30 11:44:30 +02:00
|
|
|
});
|