mojaloop / project

Repo to track product development issues for the Mojaloop project.
Other
25 stars 15 forks source link

TTK - Enable native javascript test framework for test case execution #1580

Open vijayg10 opened 4 years ago

vijayg10 commented 4 years ago

Goal:

As a Mojaloop implementer

I want to write my test cases in a stadard javascript test frame work like Jest instead of TTK's own format

so that I can use my own tools like editors and libraries in test cases

Acceptance Criteria:

Complexity: Low

Uncertainty: Medium (Design decisions may vary based on the feedback from reviewers)


Tasks: TBD

Done

Pull Requests:

Follow-up:

Dependencies:

Accountability:

vijayg10 commented 3 years ago

As per Matt's update the following code converts JS test to TTK test. https://github.com/msk-/ml-testing-toolkit/blob/feature/support-javascript-tests/src/lib/parseJsTest.js Some comments from Matt. It's not overly intelligent, but it does basically parse and analyse the structure of the js test to transform it to the TTK data format. Some notes

The code converts the following code

const syncClient = require('sync-client')
describe('Server', () => {
  it('starts', () => {
    const fspiopRequest = {
      operationPath: 'whatever',
      method: 'get',
      headers: {},
      params: {},
      apiVersion: {
        minorVersion: 1,
        majorVersion: 0,
        type: 'fspiop',
        asynchronous: false,
      },
      url: 'whatever',
    }
    const resp1 = syncClient(fspiopRequest)
    console.log('this log statement is post-request script 1')
    expect(resp1).whatever()
    const fspiopRequest2 = {
      operationPath: 'whatever',
      method: 'get',
      headers: {},
      params: {},
      apiVersion: {
        minorVersion: 1,
        majorVersion: 1,
        type: 'fspiop',
        asynchronous: false,
      },
      url: 'whatever',
    }
    const resp2 = syncClient(fspiopRequest2)
    console.log('this log statement is post-request script 2')
    expect(resp2).whatever()
    expect(resp2).whatever()
  })
})

to this

{
  "test_cases": [
    [
      {
        "operationPath": "whatever",
        "method": "get",
        "headers": {},
        "params": {},
        "apiVersion": {
          "minorVersion": 1,
          "majorVersion": 0,
          "type": "fspiop",
          "asynchronous": false
        },
        "url": "whatever",
        "tests": {
          "assertions": [
            {
              "id": 0,
              "exec": [
                "expect(resp1).whatever()"
              ],
              "description": ""
            }
          ]
        },
        "scripts": {
          "preRequest": {
            "exec": [
              "const fspiopRequest = {",
              "  operationPath: 'whatever',",
              "  method: 'get',",
              "  headers: {},",
              "  params: {},",
              "  apiVersion: {",
              "    minorVersion: 1,",
              "    majorVersion: 0,",
              "    type: 'fspiop',",
              "    asynchronous: false,",
              "  },",
              "  url: 'whatever',",
              "}"
            ]
          },
          "postRequest": {
            "exec": [
              "console.log('this log statement is post-request script 1')"
            ]
          }
        }
      },
      {
        "operationPath": "whatever",
        "method": "get",
        "headers": {},
        "params": {},
        "apiVersion": {
          "minorVersion": 1,
          "majorVersion": 1,
          "type": "fspiop",
          "asynchronous": false
        },
        "url": "whatever",
        "tests": {
          "assertions": [
            {
              "id": 0,
              "exec": [
                "expect(resp2).whatever()"
              ],
              "description": ""
            },
            {
              "id": 1,
              "exec": [
                "expect(resp2).whatever()"
              ],
              "description": ""
            }
          ]
        },
        "scripts": {
          "preRequest": {
            "exec": [
              "const fspiopRequest2 = {",
              "  operationPath: 'whatever',",
              "  method: 'get',",
              "  headers: {},",
              "  params: {},",
              "  apiVersion: {",
              "    minorVersion: 1,",
              "    majorVersion: 1,",
              "    type: 'fspiop',",
              "    asynchronous: false,",
              "  },",
              "  url: 'whatever',",
              "}"
            ]
          },
          "postRequest": {
            "exec": [
              "console.log('this log statement is post-request script 2')"
            ]
          }
        }
      }
    ]
  ]
}