datopian / ckan-integration-tests

Cypress toolkit to run integration tests against a CKAN instance
https://tech.datopian.com/ckan/
MIT License
4 stars 3 forks source link

Setup Mocha #9

Open cuducos opened 3 years ago

cuducos commented 3 years ago

For some tests (non-browser based integration tests) we need to run libraries outside of Cypress (as seen on #8). A better way to handle that would be to also have Mocha setup in parallel with Cypress.

Roadmap

Acceptance

*NOTE: Cypress still have some tests that are failing and this is not a blocker for this issue (see #12).

Reference

This is some example of what we've tried to implement using Cypress, this expresses the after and before logic intended here:

```javascript const ckanClient = require("ckanClient"); const { open } = require("frictionless.js"); const uuid = () => Math.random().toString(36).slice(2) + "_test"; const orgName = Cypress.env("ORG_NAME_SUFFIX") + uuid(); const packageName = uuid(); const headers = { authorization: Cypress.env("API_KEY"), "content-type": "application/json" }; const client = new ckanClient.Client( Cypress.env("API_KEY"), orgName, packageName, Cypress.config().baseUrl, Cypress.config().baseUrl + "/_giftless" ); describe("CKAN Client can create resource and push blob", () => { before(() => { // Create an organization cy.request({ method: "POST", url: "api/3/action/organization_create", headers: headers, body: { name: orgName } }); }); afterEach(() => { // Delete the resource (if created) cy.request({ method: "GET", url: "api/3/action/package_show?name_or_id=" + packageName, headers: headers }).then(resp => { cy.request({ method: "POST", url: "api/3/action/package_delete", headers: headers, body: { id: resp.body.result.id } }); }); }); after(() => { // Delete the organization cy.request({ method: "POST", url: "api/3/action/organization_delete", headers: headers, body: { id: orgName } }); }); it("CKAN Client: Create resource", async () => { // TODO use wrap/invoke ? let dataset = await client.create({ name: packageName, owner_org: orgName }); expect(dataset.name).to.eq(packageName); }); it("CKAN Client: Push blob (using async/await)", async () => { // first, create the resource/package const dataset = await client.create({ name: packageName, owner_org: orgName }); // then push the blob cy.fixture("sample.csv").then(async content => { const resource = open({ name: "sample.csv", data: content }); const resp = await client.pushBlob(resource); expect(resp.success).to.eq(packageName); }); }); }); ```
cuducos commented 3 years ago

@kmanaseryan, I believe @cotts and I covered the basic implementation today — justupdated this issue with this info.

I couldn't run it just yet against a live server, but maybe the instance you were troubleshooting the other day (based on ckanext-blob-storage repo) works and you can cover the items in the Acceptance tests. Feel free to jump in, here and test it, or to advance to #10 (also based on the snippet in this issue, if that helps).

kmanaseryan commented 3 years ago

@cuducos and @cotts just finished understanding the main idea in a more detailed way. I've been able to configure Cypress for my local CKAN (which actually doesn't have blob storage extension). Able to run Cypress tests, some of them are failing locally, (which we are expecting) and some of them are running. I see how Mocha is setup 👍

Today I wanted to jump into issue #10, but realized there are some work I can do in this issue. So basically this what I'm going to do next: