2023-04-04 10:46:28 +02:00
|
|
|
///<reference path="../../global.d.ts" />
|
2023-02-08 10:16:38 +01:00
|
|
|
|
|
|
|
describe('imports', () => {
|
2023-04-05 13:20:58 +02:00
|
|
|
const baseUrl = Cypress.config().baseUrl;
|
|
|
|
const randomSeed = String(Math.random()).split('.')[1];
|
|
|
|
const randomFeatureName = `cypress-features${randomSeed}`;
|
|
|
|
const userIds: any[] = [];
|
|
|
|
|
2023-02-08 10:16:38 +01:00
|
|
|
before(() => {
|
2023-04-05 13:20:58 +02:00
|
|
|
cy.runBefore();
|
2023-04-04 10:46:28 +02:00
|
|
|
cy.login_UI();
|
2023-02-08 10:16:38 +01:00
|
|
|
for (let i = 1; i <= 2; i++) {
|
|
|
|
cy.request('POST', `${baseUrl}/api/admin/user-admin`, {
|
|
|
|
name: `unleash-e2e-user${i}-${randomFeatureName}`,
|
|
|
|
email: `unleash-e2e-user${i}-${randomFeatureName}@test.com`,
|
|
|
|
sendEmail: false,
|
|
|
|
rootRole: 3,
|
2023-10-02 14:25:46 +02:00
|
|
|
}).then((response) => userIds.push(response.body.id));
|
2023-02-08 10:16:38 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
after(() => {
|
2023-10-02 14:25:46 +02:00
|
|
|
userIds.forEach((id) =>
|
|
|
|
cy.request('DELETE', `${baseUrl}/api/admin/user-admin/${id}`),
|
2023-02-08 10:16:38 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-04-04 10:46:28 +02:00
|
|
|
cy.login_UI();
|
2023-02-08 10:16:38 +01:00
|
|
|
if (document.querySelector("[data-testid='CLOSE_SPLASH']")) {
|
|
|
|
cy.get("[data-testid='CLOSE_SPLASH']").click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can import data', () => {
|
|
|
|
cy.visit('/projects/default');
|
2023-05-08 10:16:18 +02:00
|
|
|
cy.get("[data-testid='IMPORT_BUTTON']").click({ force: true });
|
2023-02-08 10:16:38 +01:00
|
|
|
|
|
|
|
const exportText = {
|
|
|
|
features: [
|
|
|
|
{
|
|
|
|
name: randomFeatureName,
|
|
|
|
description: '',
|
|
|
|
type: 'release',
|
|
|
|
project: 'default',
|
|
|
|
stale: false,
|
|
|
|
impressionData: false,
|
|
|
|
archived: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
featureStrategies: [
|
|
|
|
{
|
|
|
|
name: 'flexibleRollout',
|
|
|
|
id: '14a0d9dd-2b5d-4a21-98fd-ede72bda0328',
|
|
|
|
featureName: randomFeatureName,
|
|
|
|
parameters: {
|
|
|
|
groupId: randomFeatureName,
|
|
|
|
rollout: '50',
|
|
|
|
stickiness: 'default',
|
|
|
|
},
|
|
|
|
constraints: [],
|
|
|
|
segments: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
featureEnvironments: [
|
|
|
|
{
|
|
|
|
enabled: true,
|
|
|
|
featureName: randomFeatureName,
|
|
|
|
environment: 'test',
|
|
|
|
variants: [],
|
|
|
|
name: randomFeatureName,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
contextFields: [],
|
|
|
|
featureTags: [
|
|
|
|
{
|
|
|
|
featureName: randomFeatureName,
|
|
|
|
tagType: 'simple',
|
|
|
|
tagValue: 'best-tag',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
featureName: randomFeatureName,
|
|
|
|
tagType: 'simple',
|
|
|
|
tagValue: 'rserw',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
featureName: randomFeatureName,
|
|
|
|
tagType: 'simple',
|
|
|
|
tagValue: 'FARO',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
segments: [],
|
|
|
|
tagTypes: [
|
|
|
|
{
|
|
|
|
name: 'simple',
|
|
|
|
description: 'Used to simplify filtering of features',
|
|
|
|
icon: '#',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
cy.get("[data-testid='VALIDATE_BUTTON']").should('be.disabled');
|
|
|
|
|
2024-01-11 11:03:01 +01:00
|
|
|
cy.intercept('POST', '/api/admin/features-batch/import').as(
|
|
|
|
'featureImported',
|
|
|
|
);
|
|
|
|
|
2023-02-08 10:16:38 +01:00
|
|
|
// cypress can only work with input@file that is visible
|
|
|
|
cy.get('input[type=file]')
|
|
|
|
.invoke('attr', 'style', 'display: block')
|
|
|
|
.selectFile({
|
|
|
|
contents: Cypress.Buffer.from(JSON.stringify(exportText)),
|
|
|
|
fileName: 'upload.json',
|
|
|
|
lastModified: Date.now(),
|
|
|
|
});
|
|
|
|
cy.get("[data-testid='VALIDATE_BUTTON']").click();
|
|
|
|
cy.get("[data-testid='IMPORT_CONFIGURATION_BUTTON']").click();
|
|
|
|
|
2024-01-11 11:03:01 +01:00
|
|
|
cy.wait('@featureImported');
|
|
|
|
cy.contains('Import completed');
|
2023-05-08 10:16:18 +02:00
|
|
|
|
2024-01-11 09:56:43 +01:00
|
|
|
cy.request({
|
|
|
|
url: `/api/admin/projects/default/features/${randomFeatureName}`,
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
}).then((response) => {
|
|
|
|
expect(response.body.name).to.equal(randomFeatureName);
|
|
|
|
const devEnv = response.body.environments.find(
|
|
|
|
(env: any) => env.name === 'development',
|
|
|
|
);
|
2024-01-09 16:54:22 +01:00
|
|
|
|
2024-01-11 09:56:43 +01:00
|
|
|
expect(devEnv.name).to.equal('development');
|
|
|
|
expect(devEnv.strategies[0].parameters.rollout).to.equal('50');
|
|
|
|
expect(devEnv.enabled).to.equal(true);
|
|
|
|
});
|
2023-02-08 10:16:38 +01:00
|
|
|
});
|
|
|
|
});
|