Skip to content

Add integration tests#71

Open
GavinRay97 wants to merge 1 commit intomainfrom
gavin/integration-tests
Open

Add integration tests#71
GavinRay97 wants to merge 1 commit intomainfrom
gavin/integration-tests

Conversation

@GavinRay97
Copy link
Member

Comprehensive plan/spec committed to integration-tests/INTEGRATION-TESTS-PLAN-PROMPT.md for posterity.

Uses local ddn CLI to create a temp local supergraph and add the nodejs-lambda connector to it.
See the lifecycle description below:

  **beforeAll** (runs once):
  1. Build the ndc-lambda-sdk (`npm run build` in `../ndc-lambda-sdk`)
  2. Create temp directory for DDN project
  3. `ddn supergraph init <tempdir>/test-project`
  4. `ddn connector init myjs --hub-connector hasura/nodejs --subgraph .../app/subgraph.yaml --configure-port 9876`
  5. Copy `fixtures/functions.ts` into connector directory
  6. Patch connector's `package.json` to use `file:` reference to local SDK
  7. `npm install` in connector directory
  8. Start connector via `node ndc-lambda-sdk/bin/index.js host -f functions.ts serve --configuration ./ --port 9876`
  9. Poll `/health` until 200 OK (30s timeout)

Example output:

ndc-nodejs-lambda/integration-tests on  gavin/integration-tests via  v22.14.0
❯ npm test

> ndc-nodejs-lambda-integration-tests@1.0.0 test
> mocha

    Building ndc-lambda-sdk...
    Initializing DDN project in /tmp/ndc-lambda-integration-h7y2q6/test-project...
    Initializing connector...
    Installing connector dependencies...
    Starting connector server...
    Waiting for connector to be healthy...
    Connector is healthy.
    Updating DataConnectorLink schema...
    DataConnectorLink schema updated.
  Capabilities endpoint
    ✔ GET /capabilities returns query and mutation capabilities

  DDN supergraph build
    ✔ successfully builds the supergraph locally (1271ms)
    ✔ produces build artifacts

  DDN connector introspect
    ✔ DataConnectorLink has valid schema after manual introspection

  Error handling
    ✔ throwForbidden returns 403
    ✔ throwConflict returns 409
    ✔ throwUnprocessable returns 422
    ✔ throwInternalError returns 500
    ✔ querying a nonexistent function returns 400
    ✔ calling a procedure via query endpoint returns 400

  Health endpoint
    ✔ GET /health returns 200

  Mutation tests
    counter procedures
      ✔ resetCounter resets to zero
      ✔ incrementCounter increments the counter
      ✔ counter state persists across calls
    createUser procedure
      ✔ creates a user with name and email
      ✔ returns user with id field
    async procedure
      ✔ asyncCreateItem creates an item asynchronously

  Query tests
    scalar types
      ✔ hello with no args returns default greeting
      ✔ hello with name arg returns personalized greeting
      ✔ add returns sum of two numbers
      ✔ isTrue returns boolean correctly
      ✔ echoBigInt echoes back a bigint value
    nullable and optional arguments
      ✔ greetNullable with null returns anonymous
      ✔ greetNullable with a value returns greeting
      ✔ greetOptional with no args returns default
      ✔ greetOptional with a value returns greeting
    array types
      ✔ sumArray returns sum of number array
      ✔ reverseStrings returns reversed array
    object types
      ✔ getDistance computes distance between coordinates
      ✔ describePlace returns a description string
    nested return types
      ✔ getPersonWithAddress returns nested object with field selection
    async functions
      ✔ asyncGreet returns async greeting
      ✔ asyncGetPlace returns async place object
    variables
      ✔ executes query with variable arguments for each variable set
      ✔ mixes literal and variable arguments

  Schema endpoint
    ✔ returns functions and procedures
    ✔ contains scalar type definitions
    ✔ contains object type definitions
    functions (queries)
      ✔ includes hello function
      ✔ includes add function
      ✔ includes isTrue function
      ✔ includes echoBigInt function
      ✔ includes nullable and optional argument functions
      ✔ includes object-arg functions
      ✔ includes array functions
      ✔ includes async functions
      ✔ includes error-throwing functions
    procedures (mutations)
      ✔ includes incrementCounter
      ✔ includes resetCounter
      ✔ includes createUser
      ✔ includes asyncCreateItem

    Stopping connector server...
    Cleaning up temp directory...

  51 passing (16s)

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

Successfully merging this pull request may close these issues.

1 participant