{"_id":"@aqovia/insomnia-api-helper","name":"@aqovia/insomnia-api-helper","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@aqovia/insomnia-api-helper","version":"0.0.1","description":"A library for using an Insomnia API design document's requests within JavaScript","author":{"name":"RA"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Aqovia/insomnia-api-helper.git"},"type":"module","main":"index.js","module":"index.js","exports":{".":{"import":{"default":"./index.js"}},"./package.json":"./package.json"},"scripts":{},"dependencies":{},"devDependencies":{},"peerDependencies":{},"_id":"@aqovia/insomnia-api-helper@0.0.1","bugs":{"url":"https://github.com/Aqovia/insomnia-api-helper/issues"},"homepage":"https://github.com/Aqovia/insomnia-api-helper#readme","_nodeVersion":"20.7.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-FAEXNozBFxNbXXSuEt9AbkSER+XcnAehjfLrczoI7RAwxXyAZC3nCsLNfyE2iBiaDXCWjEG5WWy2yhHjof7KtA==","shasum":"776efcf8af906ad34ec01ff117784d5bbff1528a","tarball":"https://registry.npmjs.org/@aqovia/insomnia-api-helper/-/insomnia-api-helper-0.0.1.tgz","fileCount":6,"unpackedSize":9263,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDGgG2TCr+5eUsF3qx5lhV1nrld5iRvubueUrSPKCUlJwIhAJFW7NiCsipUGCGZPzsbF7bTmY8d/wgQZtD5+Fi21hdd"}]},"_npmUser":{"name":"rickyattiliaaq","email":"ricky.attilia@aqovia.com"},"directories":{},"maintainers":[{"name":"rickyattiliaaq","email":"ricky.attilia@aqovia.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/insomnia-api-helper_0.0.1_1710775273476_0.4703152412989915"},"_hasShrinkwrap":false}},"time":{"created":"2024-03-18T15:21:13.339Z","0.0.1":"2024-03-18T15:21:13.616Z","modified":"2024-03-18T15:21:14.228Z"},"maintainers":[{"name":"rickyattiliaaq","email":"ricky.attilia@aqovia.com"}],"description":"A library for using an Insomnia API design document's requests within JavaScript","homepage":"https://github.com/Aqovia/insomnia-api-helper#readme","repository":{"type":"git","url":"git+https://github.com/Aqovia/insomnia-api-helper.git"},"author":{"name":"RA"},"bugs":{"url":"https://github.com/Aqovia/insomnia-api-helper/issues"},"license":"MIT","readme":"# Insomnia API Helper\n\nA library for using an Insomnia API design document's requests within JavaScript, e.g. for testing\n\n## Using The Library\n\n### Create An API Instance\n1. Export your Insomnia API design document as an Insomnia v4 JSON file\n2. Import/parse the JSON file into your project as an object\n3. Construct an instance of the API using:\n```javascript\nconst myApi = new InsomniaApi(jsonApiObject, optionalNameOfEnvironmentToUse);\n```\nAn instance will be created with all environment variables instantiated as per your selected environment.\n\n### Environment Variables\nWhen making requests, environment variable placeholders in the request will automatically be populated, as per your selected environment.\nEnvironment variables can be accessed (and changed) via the `myApi.envVars` object.\n\nYou can also call `myApi.setEnvironment(environmentName)` to refresh all environment variables as per the specified environment.\n\n### Auth\nIf required, set an OAuth2 token on the API, which will be used in all requests:\n```javascript\nmyApi.setAuthToken(myAuthToken);\n```\n\n### Requests\n\n####\nCreate an instance of a request that is defined in your design document by its name, and modify it as required:\n```javascript\nconst updateRequest = myApi.getRequestByName(\"Update User By ID\");\n```\n\n#### Set Path Parameters\n```javascript\nupdateRequest.pathParameters[\"id\"] = \"101\";\n```\n\n#### Set Query Parameters\n```javascript\nupdateRequest.queryParameters[\"someQueryParameter\"] = \"value\";\n```\n\n#### Set Body\n```javascript\nupdateRequest.body = {\n  firstName: \"John\",\n  lastName: \"Smith\",\n  email: \"johnsmith@mydomain.com\"\n};\n```\n\n#### Send Request\n```javascript\nconst response = await updateRequest.send();\n```\nNote. This makes and returns a `fetch` request/response.\n\n\n\n## Example Usage\n\n```javascript\nimport { InsomniaApi } from \"@aqovia/insomnia-api-helper\";\nimport usersApiDesignDocument from \"./users-api.json\" assert { type: \"json\" }; // an exported Insomnia v4 JSON design document\nimport { expect } from \"chai\";\n\ndescribe(\"Users API\", function () {\n  const environment = process.env.SELECTED_ENVIRONMENT || \"Test\";\n  const usersApi = new InsomniaApi(usersApiDesignDocument, environment);\n\n  before(async function () {\n    const authToken = await getAuthToken( // your own custom logic to retrieve an auth token\n      usersApi.envVars[\"tokenUrl\"],\n      usersApi.envVars[\"clientId\"],\n      usersApi.envVars[\"clientSecret\"]\n    );\n\n    usersApi.setAuthToken(authToken);\n  });\n\n  let newUser;\n\n  it(\"should create a user\", async function () {\n    newUser = {\n      email: \"newuser@mydomain.com\",\n      firstName: \"John\",\n      lastName: \"Smith\",\n      phone: \"12345\",\n    };\n\n    const createUserRequest = usersApi.getRequestByName(\"Create A User\");\n    createUserRequest.body = { ...createUserRequest.body, ...newUser };\n    \n    const createUserResponse = await createUserRequest.send();\n    expect(createUserResponse.status).to.equal(201);\n\n    const createUserResponseBody = await createUserResponse.json();\n    expect(createUserResponseBody).to.have.property(\"id\");\n    \n    newUser.id = createUserResponseBody.id;\n  });\n\n  it(\"should retrieve a user by ID\", async function () {\n    const getUserRequest = usersApi.getRequestByName(\"Get User By ID\");\n    getUserRequest.pathParameters.id = newUser.id;\n    \n    const getUserResponse = await getUserRequest.send();\n    expect(getUserResponse.status).to.equal(200);\n\n    const getUserResponseBody = await getUserResponse.json();\n    expect(getUserResponseBody.email).to.equal(newUser.email);\n  });\n});\n```\n","readmeFilename":"README.md"}