Skip to content

Commit

Permalink
Update collection upload tests
Browse files Browse the repository at this point in the history
Update collection upload tests

This one is levearging #1536 to generate the collections.

Also update the hub collection update command, and delete collection and related namespace after test.
  • Loading branch information
nixocio committed Feb 5, 2024
1 parent c6f2ddf commit 1f90430
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 63 deletions.
69 changes: 25 additions & 44 deletions cypress/e2e/hub/collections.cy.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,57 @@
// @ts-nocheck
import { randomString } from '../../../framework/utils/random-string';
import { hubAPI } from '../../support/formatApiPathForHub';
import { Collections } from './constants';

describe.skip('Collections- List View', () => {
describe('Collections- List View', () => {
//**Important to know:
//**In order to upload a collection, a namespace must first exist containing the first word of the collection file name
//**The only way to get rid of a collection's artifact is to choose the following option:
//**Delete entire collection from repository
//**If the artifact isn't deleted when the collection is deleted, and a user tries to create
//**a new collection by uploading the same file again, Hub will not allow it.
let namespace: string;

before(() => {
namespace = 'hub_e2e_col_namespace' + randomString(5).toLowerCase();
cy.hubLogin();
cy.getNamespace(namespace);
cy.addAndApproveMultiCollections(1);
});

it('it should render the collections page', () => {
cy.navigateTo('hub', Collections.url);
cy.verifyPageTitle(Collections.title);
});

after(() => {
cy.cleanupCollections(namespace, 'community');
cy.deleteNamespace(namespace);
});

it.skip('user can upload and then delete a new collection', () => {
cy.getOrCreateCollection().then((thisCollection) => {
const thisCollectionName = thisCollection?.split('-').slice(-2, -1).toString();
it('user can upload and delete collection', () => {
const namespace = `upload_namespace_${randomString(3, undefined, { isLowercase: true })}`;
cy.createNamespace(namespace);
const collection = randomString(5, undefined, { isLowercase: true }).replace(/\d/g, '');
cy.galaxykit(`collection upload ${namespace} ${collection} --skip-upload`).then((result) => {
cy.navigateTo('hub', Collections.url);
cy.verifyPageTitle(Collections.title);
cy.get('[data-cy="upload-collection"]').click();
cy.uploadHubCollectionFile(`collection-files/` + thisCollection, thisCollection);
const filePath = result?.filename as string;
cy.uploadHubCollectionFile(filePath);
cy.get('input[id="radio-non-pipeline"]').click();
cy.get('[data-cy="row-0"]').within(() => {
cy.get('input').click();
});
cy.intercept('POST', hubAPI`/v3/plugin/ansible/content/community/collections/artifacts/`).as(
'collection'
);
cy.get('[data-cy="Submit"]').click();
cy.wait('@collection').then((resp) => {
expect(resp?.response?.statusCode).to.eql(202);
expect(resp?.response?.statusMessage).to.eql('Accepted');
expect(resp?.responseWaited).to.eql(true);
});
cy.reload();
cy.get('[data-cy="hub-collections"]').click();
cy.clickButton(/^Clear all filters$/);
cy.navigateTo('hub', Collections.url);
cy.url().should('include', 'collections');
cy.verifyPageTitle(Collections.title);
cy.get('[data-cy="app-description"]').should(
'contain',
'Collections are a packaged unit of Ansible content that includes roles, modules, plugins, and other components, making it easier to share and reuse automation functionality.'
);
cy.get('[data-cy="table-view"]').click();
cy.clickTableRowKebabAction(thisCollectionName, 'delete-entire-collection-from-system');
cy.get('[data-ouia-component-id="confirm"]').click();
cy.intercept(
'DELETE',
hubAPI`/v3/plugin/ansible/content/community/collections/index/${namespace}/${thisCollectionName}/`
).as('deleted');
cy.get('[data-ouia-component-id="submit"]').click();
cy.wait('@deleted').then((deleted) => {
expect(deleted?.response?.statusCode).to.eq(202);
});
cy.searchAndDisplayResource(collection);
cy.get('[data-cy="actions-column-cell"]').click();
cy.get('[data-cy="delete-entire-collection-from-system"]').click({ force: true });
cy.get('#confirm').click();
cy.clickButton(/^Delete collections/);
cy.contains(/^Success$/);
cy.clickButton(/^Close$/);
cy.clickButton(/^Clear all filters$/);

cy.deleteNamespace(namespace);
});
});

it('it should render the collections page', () => {
cy.navigateTo('hub', Collections.url);
cy.verifyPageTitle(Collections.title);
});

it('should call galaxykit without error', () => {
cy.galaxykit('collection -h');
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ declare global {
failOnStatusCode?: boolean;
}
): Cypress.Chainable<void>;
uploadHubCollectionFile(hubFilePath: string, hubFileName: string): Cypress.Chainable<void>;
uploadHubCollectionFile(hubFilePath: string): Cypress.Chainable<void>;
createNamespace(namespaceName: string): Cypress.Chainable<void>;
getNamespace(namespaceName: string): Cypress.Chainable<void>;
deleteNamespace(namespaceName: string): Cypress.Chainable<void>;
Expand Down
34 changes: 16 additions & 18 deletions cypress/support/hub-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { escapeForShellCommand } from './utils';

const apiPrefix = Cypress.env('HUB_API_PREFIX') as string;

// GalaxyKit Integration: To invoke `galaxykit` commands for generating resources
// GalaxyKit Integration: To invoke `galaxykit` commands for generating resource
Cypress.Commands.add('galaxykit', (operation: string, ...args: string[]) => {
const adminUsername = Cypress.env('HUB_USERNAME') as string;
const adminPassword = Cypress.env('HUB_PASSWORD') as string;
Expand All @@ -37,9 +37,15 @@ Cypress.Commands.add('galaxykit', (operation: string, ...args: string[]) => {
}
});

cy.log(`stdout: ${stdout}`).then(() => {
return stdout.split('\n').filter((s) => !!s);
});
cy.log(`stdout: ${stdout}`);

let parsedStdout: unknown;
try {
parsedStdout = JSON.parse(stdout);
} catch (e) {
parsedStdout = stdout.split('\n').filter((s) => !!s);
}
return cy.wrap(parsedStdout);
});
});

Expand Down Expand Up @@ -87,20 +93,12 @@ Cypress.Commands.add(
}
);

Cypress.Commands.add('uploadHubCollectionFile', (hubFilePath: string, hubFileName: string) => {
cy.fixture(hubFilePath, 'binary')
.then(Cypress.Blob.binaryStringToBlob)
.then((fileContent) => {
cy.get('input[id="file-upload-file-filename"]').attachFile(
{
fileContent,
fileName: hubFileName,
filePath: hubFilePath,
mimeType: 'application/gzip',
},
{ subjectType: 'drag-n-drop' }
);
});
Cypress.Commands.add('uploadHubCollectionFile', (hubFilePath: string) => {
cy.get('[data-cy="upload-collection"]').click();
cy.get('#file-upload-file-browse-button').click();
cy.get('input[id="file-upload-file-filename"]').selectFile(hubFilePath, {
action: 'drag-drop',
});
});

Cypress.Commands.add('addAndApproveMultiCollections', (numberOfCollections = 1) => {
Expand Down

0 comments on commit 1f90430

Please sign in to comment.