Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Mocha #9

Open
3 of 10 tasks
cuducos opened this issue Nov 24, 2020 · 2 comments
Open
3 of 10 tasks

Setup Mocha #9

cuducos opened this issue Nov 24, 2020 · 2 comments

Comments

@cuducos
Copy link
Contributor

cuducos commented Nov 24, 2020

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

  • Install Mocha DONE fc4e4ec
  • Add before hook to create an organization DONE f8dc86f
  • Addd after hook to delete the organization DONE f8dc86f
  • Update the README according to new Mocha tests - @cotts
  • Update the README to explain when to use Mocha and when to use Cypress (as per the issue description) - @kmanaseryan
  • Create a generic env config which will be reused by Cypress and Mocha - @cotts

Acceptance

  • Mocha does not leave data behind (it creates and deletes organization and resources)
  • Mocha and Cypress work*
  • There are instructions to run Mocha in this repository (docs)
  • There are clear instructions for developers to understand when use Cypress and when use Mocha

*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:

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
Copy link
Contributor Author

cuducos commented Nov 24, 2020

@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
Copy link

kmanaseryan commented Nov 25, 2020

@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:

  • Use the above snippet for Mocha tests. I see the current one we have is just a "test" test.
  • Update the README according to new Mocha tests
  • Update the README to explain when to use Mocha and when to use Cypress (as per the issue description)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants