Testing

Unit Testing

We made sure to have unit tests for both our UI as well as our npm packages to ensure that each function behaved as expected and can clear out any hidden bugs.

The main testing library that we used was jest as it is compatible with multiple frameworks such as React and NodeJS and it provides mocking to make our own mock functions.

Voiceflow to UBF

When it came to testing vf-to-ubf, we have to unit test two main components. First, the functions used for validation of the Voiceflow file and second are the functions used for building the UBF.

vfToUbf

For testing validation, we went through the process of inputting a set of Voiceflow diagrams - whether it be an empty diagram, a diagram with extra keys, a diagram with missing keys - and making sure we don’t miss a case where theoretically validation could fail.

test("Voiceflow Diagram contains unsupported type", () => {
    diagram = JSON.parse(largeDiagrams.getUnsupportedType())
    validate.validateDiagram(diagram).then(resp => {
        expect(resp).toBe(false)
    })
})

It is very important to ensure that the JSON schema that we are using to validate the Voiceflow diagram doesn’t provide any false positives and having these robust unit tests makes sure this is the case.

UBF to Twilio

A similar approach was taken to test the components when it comes to building the UBF.

test("Fetch Deployed Bots on valid account", () => {
    client = {"accountSid":"valid", "authKey":"valid"}
    deployed.getDeployedBots(client).then(resp => {
        expect(resp).toEqual([{"phoneNumber": "+447958293912", "name": "test-1", "id": "test-1", "diagram": null, "timestamp": "1"}, {"phoneNumber":"+447942960231", "name": "test-2", "id": "test-2", "diagram": null, "timestamp": "1"}])
    })
})

For unit testing ubf-to-twilio, it was a bit more tricky as part of the package is making external API calls to Twilio and the purpose of a unit test is to test a module in isolation. To enable that, we used jest to mock specific API calls. The purpose of the mocks is to emulate what Twilio would respond if we were to make the same call in a live environment.

The Frontend

The UI unit tests were responsible for ensuring that everything on the frontend works as expected. They were written to check that pages displayed the correct info and core elements relevant to the user experience, such as text data, buttons, and written instructions to help guide the user on some pages.

Components were also tested to ensure they processed and displayed data correctly based on certain user inputs. An example of this is checking the UI for notifications relating to error validation on the upload chatbot page.

To test components that require calling our API, we would also mock those functionalities using jest mocks so that every test is isolated to each component.