How to use the @airtasker/spot.test function in @airtasker/spot

To help you get started, we’ve selected a few @airtasker/spot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github airtasker / spot / lib / src / testing / __examples__ / default-response.ts View on Github external
@request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @defaultResponse
  defaultResponse(@body body: DefaultErrorBody) {}

  @test(
    {
      request: {
        body: {
          private: true
        }
      },
      response: {
        status: 400
      }
    },
    { allowInvalidRequest: true }
  )
  defaultResponseTest() {}
}

interface CreateCompanyRequestBody {
github airtasker / spot / lib / src / testing / __examples__ / draft-endpoint.ts View on Github external
@api({ name: "company-api" })
class CompanyApi {}

@draft
@endpoint({
  method: "POST",
  path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(@body body: CompanyBody) {}

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}
}

interface CreateCompanyRequestBody {
  name: String;
  private: boolean;
github airtasker / spot / lib / src / testing / __examples__ / single-provider-state.ts View on Github external
method: "GET",
  path: "/companies/:companyId"
})
class GetCompany {
  @request
  request(
    @pathParams
    pathParams: {
      companyId: String;
    }
  ) {}

  @response({ status: 200 })
  successResponse(@body body: CompanyBody) {}

  @test({
    states: [{ name: "a company exists", params: { id: "abc" } }],
    request: {
      pathParams: {
        companyId: "abc"
      }
    },
    response: {
      status: 200
    }
  })
  successResponseTest() {}
}

interface CompanyBody {
  name: String;
  employeeCount: Integer;
github airtasker / spot / lib / src / testing / __examples__ / no-provider-states.ts View on Github external
path: "/companies"
})
class CreateCompany {
  @request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}
}

interface CreateCompanyRequestBody {
  name: String;
  private: boolean;
github airtasker / spot / lib / src / testing / __examples__ / multiple-tests.ts View on Github external
@request
  request(@body body: CreateCompanyRequestBody) {}

  @response({ status: 201 })
  successResponse(
    @headers
    headers: {
      Location: String;
    },
    @body body: CompanyBody
  ) {}

  @response({ status: 400 })
  badRequestResponse(@body body: ErrorBody) {}

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}

  @test(
    {
      request: {
        body: {
github airtasker / spot / lib / src / testing / __examples__ / multiple-tests.ts View on Github external
badRequestResponse(@body body: ErrorBody) {}

  @test({
    request: {
      body: {
        name: "My Company",
        private: true
      }
    },
    response: {
      status: 201
    }
  })
  successResponseTest() {}

  @test(
    {
      request: {
        body: {
          name: 5
        }
      },
      response: {
        status: 400
      }
    },
    { allowInvalidRequest: true }
  )
  badRequestTest() {}
}

interface CreateCompanyRequestBody {
github airtasker / spot / lib / src / testing / __examples__ / object-query-param.ts View on Github external
method: "GET",
  path: "/companies"
})
class GetCompanies {
  @request
  request(
    @queryParams
    queryParam: {
      profile?: { name: String };
    }
  ) {}

  @response({ status: 200 })
  successResponse(@body body: CompanyBody[]) {}

  @test({
    request: {
      queryParams: {
        profile: {
          name: "testname"
        }
      }
    },
    response: {
      status: 200
    }
  })
  successResponseTest() {}
}

interface CompanyBody {
  name: String;
github airtasker / spot / lib / src / testing / __examples__ / multiple-provider-states.ts View on Github external
path: "/companies/:companyId/users/:userId"
})
class GetUser {
  @request
  request(
    @pathParams
    pathParams: {
      companyId: String;
      userId: String;
    }
  ) {}

  @response({ status: 200 })
  successResponse(@body body: UserBody) {}

  @test({
    states: [
      { name: "a company exists", params: { id: "abc" } },
      { name: "a user exists", params: { id: "def", companyId: "abc" } }
    ],
    request: {
      pathParams: {
        companyId: "abc",
        userId: "def"
      }
    },
    response: {
      status: 200
    }
  })
  successResponseTest() {}
}
github airtasker / spot / lib / src / __examples__ / contract-endpoint.ts View on Github external
headers: {
      /** Location header */
      Location: String;
    },
    /** User response body */
    @body body: UserBody
  ) {}

  /** Bad request response */
  @response({ status: 404 })
  badRequestResponse(
    /** Error response body */
    @body body: ErrorBody
  ) {}

  @test({
    states: [{ name: "userExists", params: { id: 101 } }],
    request: {
      headers: {
        "x-auth-token": "sometoken"
      },
      pathParams: {
        companyId: "company",
        userId: "user"
      }
    },
    response: { status: 201 }
  })
  successResponseTest() {}
}
github airtasker / spot / lib / src / __examples__ / contract.ts View on Github external
) {}

  /** Bad request response */
  @response({ status: 400 })
  badRequestResponse(
    /** Error response body */
    @body body: ErrorBody
  ) {}

  @defaultResponse
  unexpectedResponse(
    /** Error response body */
    @body body: ErrorBody
  ) {}

  @test({
    request: {
      pathParams: {
        companyId: "abc"
      },
      headers: {
        "x-auth-token": "hellotoken"
      },
      body: {
        data: {
          firstName: "John",
          lastName: "Snow",
          age: 15,
          email: "johnsnow@spot.com",
          address: "some address"
        }
      }

@airtasker/spot

**Spot** (_"Single Point Of Truth"_) is a concise, developer-friendly way to describe your API contract.

MIT
Latest version published 5 months ago

Package Health Score

72 / 100
Full package analysis

Similar packages