Skip to content

Instantly share code, notes, and snippets.

@shwetaneelsharma
Last active November 4, 2020 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shwetaneelsharma/e0c2fa9f84a5e5e5abd4b08b4f4685fd to your computer and use it in GitHub Desktop.
Save shwetaneelsharma/e0c2fa9f84a5e5e5abd4b08b4f4685fd to your computer and use it in GitHub Desktop.
create topic via JSON
import {
BULK_TEST_TOPICS, BULK_TEST_TOPICS_NAMES, POST_RESPONSE_TWO_NOT_ONE, CREATED_TOPICS_URL
} from '../fixtures/topic_testdata'
import {
getfirstTopicTitle, getfirstTopicType
} from '../page-objects/create_topic'
describe('Topic Creation Via Json:API', function () {
before(function () {
cy.createUser(Cypress.env('cyAdminUser'), Cypress.env('cyAdminPassword'), Cypress.env('cyAdminRole'));
})
it('Create bulk topics & Verify them using json:api', function () {
for (let i = 0; i < BULK_TEST_TOPICS.length; i++) {
let BULK_TEST_JSON_OBJECT = BULK_TEST_TOPICS[i];
cy.getRestToken(Cypress.env('cyAdminUser'), Cypress.env('cyAdminPassword')).then(token => {
cy.getNodesWithTitle(token, 'topic', BULK_TEST_JSON_OBJECT.data.attributes.title.value)
.then(nodes => {
nodes.map(function (node) {
cy.deleteNode(token, 'topic', node.id);
});
});
cy.createTopic(token, BULK_TEST_JSON_OBJECT)
}).then(res => {
expect(res.status).to.eq(POST_RESPONSE_TWO_NOT_ONE);
expect(res.body.data.attributes.body.value).to.eq(BULK_TEST_JSON_OBJECT.data.attributes.title.value);
});
cy.logout();
cy.visit(CREATED_TOPICS_URL);
getfirstTopicTitle().should('have.text', BULK_TEST_JSON_OBJECT.data.attributes.title.value);
getfirstTopicType().should('have.text', BULK_TEST_TOPICS_NAMES[i]);
}
});
after(function () {
cy.deleteUser(Cypress.env('cyAdminUser'));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment