diff --git a/README.md b/README.md index a6edd3b..cc0f52f 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,67 @@ const gocardless = require('gocardless-nodejs'); const { Environments } = require('gocardless-nodejs'); ``` +### Handling webhooks + +GoCardless supports webhooks, allowing you to receive real-time notifications when things happen in your account, so you can take automatic actions in response, for example: + +* When a customer cancels their mandate with the bank, suspend their club membership +* When a payment fails due to lack of funds, mark their invoice as unpaid +* When a customer's subscription generates a new payment, log it in their "past payments" list + +The client allows you to validate that a webhook you receive is genuinely from GoCardless, and to parse it into `Event` objects which are easy to work with: + +```typescript +import { webhooks } from 'gocardless-nodejs'; + +// When you create a webhook endpoint, you can specify a secret. When GoCardless sends +// you a webhook, it will sign the body using that secret. Since only you and GoCardless +// know the secret, you can check the signature and ensure that the webhook is truly +// from GoCardless. +const webhookEndpointSecret = process.env.GOCARDLESS_WEBHOOK_ENDPOINT_SECRET; + +// In your webhook handler (e.g. Express route) +app.post('/webhooks', (req, res) => { + try { + const events = webhooks.parse( + req.body, + webhookEndpointSecret, + req.headers['webhook-signature'] + ); + + events.forEach((event) => { + console.log(event.id); + }); + + res.status(200).end(); + } catch (e) { + if (e.name === 'InvalidSignatureError') { + // The webhook doesn't appear to be genuinely from GoCardless + res.status(498).end(); + } + throw e; + } +}); +``` + +#### Accessing the webhook ID + +If you need to access the webhook ID for debugging purposes, you can use `parseWithMeta` instead: + +```typescript +const result = webhooks.parseWithMeta( + req.body, + webhookEndpointSecret, + req.headers['webhook-signature'] +); +const events = result.events; +const webhookId = result.webhookId; // e.g. "WB123" - useful for debugging +``` + +Note: The webhook ID is intended for debugging and logging purposes only. It should not be used for deduplication - instead, use the event IDs to deduplicate, as each event has a unique ID that remains consistent if the same event is sent multiple times. + +For more details on working with webhooks, see our ["Getting started" guide](https://developer.gocardless.com/getting-started/api/introduction/?lang=node). + ## Upgrading from older versions If you're upgrading from v7 or earlier to v8 or later, see: MIGRATION_V8.md diff --git a/package-lock.json b/package-lock.json index cbcead1..3cba2f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1289,16 +1289,22 @@ } }, "node_modules/@napi-rs/wasm-runtime": { - "version": "0.2.12", - "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.12.tgz", - "integrity": "sha512-ZVWUcfwY4E/yPitQJl481FjFo3K22D6qF0DuFH6Y/nbnE11GY5uguDxZMGXPQ8WQ0128MXQD7TnfHyK4oWoIJQ==", + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.4.tgz", + "integrity": "sha512-3NQNNgA1YSlJb/kMH1ildASP9HW7/7kYnRI2szWJaofaS1hWmbGI4H+d3+22aGzXXN9IJ+n+GiFVcGipJP18ow==", "dev": true, "license": "MIT", "optional": true, "dependencies": { - "@emnapi/core": "^1.4.3", - "@emnapi/runtime": "^1.4.3", - "@tybys/wasm-util": "^0.10.0" + "@tybys/wasm-util": "^0.10.1" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "peerDependencies": { + "@emnapi/core": "^1.7.1", + "@emnapi/runtime": "^1.7.1" } }, "node_modules/@nodelib/fs.scandir": { @@ -1912,9 +1918,9 @@ "license": "ISC" }, "node_modules/@unrs/resolver-binding-android-arm-eabi": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-android-arm-eabi/-/resolver-binding-android-arm-eabi-1.11.1.tgz", - "integrity": "sha512-ppLRUgHVaGRWUx0R0Ut06Mjo9gBaBkg3v/8AxusGLhsIotbBLuRk51rAzqLC8gq6NyyAojEXglNjzf6R948DNw==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-android-arm-eabi/-/resolver-binding-android-arm-eabi-1.12.2.tgz", + "integrity": "sha512-g5T90pqg1bo/7mytQx6F4iBNC0Wsh9cu+z9veDbFjc7HjpesJFWD7QMS0NGStXM075+7dJPPVvBbpZlnrdpi/w==", "cpu": [ "arm" ], @@ -1926,9 +1932,9 @@ ] }, "node_modules/@unrs/resolver-binding-android-arm64": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-android-arm64/-/resolver-binding-android-arm64-1.11.1.tgz", - "integrity": "sha512-lCxkVtb4wp1v+EoN+HjIG9cIIzPkX5OtM03pQYkG+U5O/wL53LC4QbIeazgiKqluGeVEeBlZahHalCaBvU1a2g==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-android-arm64/-/resolver-binding-android-arm64-1.12.2.tgz", + "integrity": "sha512-YGCRZv/9GLhwmz6mYDeTsm/92BAyR28l6c2ReweVW5pWgfsitWLY8upvfRlGdoyD8HjeTHSYJWyZGD4KJA/nFQ==", "cpu": [ "arm64" ], @@ -1940,9 +1946,9 @@ ] }, "node_modules/@unrs/resolver-binding-darwin-arm64": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-darwin-arm64/-/resolver-binding-darwin-arm64-1.11.1.tgz", - "integrity": "sha512-gPVA1UjRu1Y/IsB/dQEsp2V1pm44Of6+LWvbLc9SDk1c2KhhDRDBUkQCYVWe6f26uJb3fOK8saWMgtX8IrMk3g==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-darwin-arm64/-/resolver-binding-darwin-arm64-1.12.2.tgz", + "integrity": "sha512-u9DiNT1auQMO20A9SyTuG3wUgQWB9Z7KjAg0uFuCDR1FsAY8A0CG2S6JpHS1xwm/w1G08bjXZDcyOCjv1WAm2w==", "cpu": [ "arm64" ], @@ -1954,9 +1960,9 @@ ] }, "node_modules/@unrs/resolver-binding-darwin-x64": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-darwin-x64/-/resolver-binding-darwin-x64-1.11.1.tgz", - "integrity": "sha512-cFzP7rWKd3lZaCsDze07QX1SC24lO8mPty9vdP+YVa3MGdVgPmFc59317b2ioXtgCMKGiCLxJ4HQs62oz6GfRQ==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-darwin-x64/-/resolver-binding-darwin-x64-1.12.2.tgz", + "integrity": "sha512-f7rPLi/T1HVKZu/u6t87lroib16n8vrSzcyxI7lg4BGO9UF26KhQL44sd9eOUgrTYhvRXtWOIZT5PejdPyJfUA==", "cpu": [ "x64" ], @@ -1968,9 +1974,9 @@ ] }, "node_modules/@unrs/resolver-binding-freebsd-x64": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-freebsd-x64/-/resolver-binding-freebsd-x64-1.11.1.tgz", - "integrity": "sha512-fqtGgak3zX4DCB6PFpsH5+Kmt/8CIi4Bry4rb1ho6Av2QHTREM+47y282Uqiu3ZRF5IQioJQ5qWRV6jduA+iGw==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-freebsd-x64/-/resolver-binding-freebsd-x64-1.12.2.tgz", + "integrity": "sha512-BpcOjWCJub6nRZUS2zA20pmLvjtqAtGejETaIyRLiZiQf++cbrjltLA5NN/xaXfqeOBOSlMFbemIl5/S5tljmg==", "cpu": [ "x64" ], @@ -1982,9 +1988,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-arm-gnueabihf": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm-gnueabihf/-/resolver-binding-linux-arm-gnueabihf-1.11.1.tgz", - "integrity": "sha512-u92mvlcYtp9MRKmP+ZvMmtPN34+/3lMHlyMj7wXJDeXxuM0Vgzz0+PPJNsro1m3IZPYChIkn944wW8TYgGKFHw==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm-gnueabihf/-/resolver-binding-linux-arm-gnueabihf-1.12.2.tgz", + "integrity": "sha512-vZTDvdSISZjJx66OzJqtsOhzifbqRjbmI1Mnu49fQDwog5GtDI4QidRiEAYbZCRj9C8YZEW+3ZjqsyS9GR4k2A==", "cpu": [ "arm" ], @@ -1996,9 +2002,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-arm-musleabihf": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm-musleabihf/-/resolver-binding-linux-arm-musleabihf-1.11.1.tgz", - "integrity": "sha512-cINaoY2z7LVCrfHkIcmvj7osTOtm6VVT16b5oQdS4beibX2SYBwgYLmqhBjA1t51CarSaBuX5YNsWLjsqfW5Cw==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm-musleabihf/-/resolver-binding-linux-arm-musleabihf-1.12.2.tgz", + "integrity": "sha512-BiPI+IrIlwcW4nLLMM21+B1dFPzd55yAVgVGrdgDjNef+ch03GdxrcyaIz8X9SsQirh/kCQ7mviyWlMxdh2D7g==", "cpu": [ "arm" ], @@ -2010,9 +2016,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-arm64-gnu": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm64-gnu/-/resolver-binding-linux-arm64-gnu-1.11.1.tgz", - "integrity": "sha512-34gw7PjDGB9JgePJEmhEqBhWvCiiWCuXsL9hYphDF7crW7UgI05gyBAi6MF58uGcMOiOqSJ2ybEeCvHcq0BCmQ==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm64-gnu/-/resolver-binding-linux-arm64-gnu-1.12.2.tgz", + "integrity": "sha512-zJc0H99FEPoFfSrNpa91HYfxzfAJCr502oxNK1cfdC9hlaFI43RT+JFCann9JUgZmLzzntChHyn13Sgn9ljHNg==", "cpu": [ "arm64" ], @@ -2024,9 +2030,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-arm64-musl": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm64-musl/-/resolver-binding-linux-arm64-musl-1.11.1.tgz", - "integrity": "sha512-RyMIx6Uf53hhOtJDIamSbTskA99sPHS96wxVE/bJtePJJtpdKGXO1wY90oRdXuYOGOTuqjT8ACccMc4K6QmT3w==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-arm64-musl/-/resolver-binding-linux-arm64-musl-1.12.2.tgz", + "integrity": "sha512-KQ3Lki6l+Pz1k/eBipN41ES+YUK30beLGb9YqcB1O542cyLCNE6GaxrfcY3T6EezmGGk84wb5XyO9loTM9tkcA==", "cpu": [ "arm64" ], @@ -2037,10 +2043,38 @@ "linux" ] }, + "node_modules/@unrs/resolver-binding-linux-loong64-gnu": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-loong64-gnu/-/resolver-binding-linux-loong64-gnu-1.12.2.tgz", + "integrity": "sha512-3SJGEh1DborhG6pyxvhPzCT4bbSIVihsvgJc13P1bHG7KLdNDaF9T3gsTwFc7Jw/5Y5/iWOjkEx7Zy0NvCGX3Q==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@unrs/resolver-binding-linux-loong64-musl": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-loong64-musl/-/resolver-binding-linux-loong64-musl-1.12.2.tgz", + "integrity": "sha512-jiuG/Obbel7uw1PwHNFfrkiKhLAF6mnyZ6aWlOAVN9WqKm8v0OFGnciJIHu8+CMvXLQ8AD51LPzAoUfT21D5Ew==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, "node_modules/@unrs/resolver-binding-linux-ppc64-gnu": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-ppc64-gnu/-/resolver-binding-linux-ppc64-gnu-1.11.1.tgz", - "integrity": "sha512-D8Vae74A4/a+mZH0FbOkFJL9DSK2R6TFPC9M+jCWYia/q2einCubX10pecpDiTmkJVUH+y8K3BZClycD8nCShA==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-ppc64-gnu/-/resolver-binding-linux-ppc64-gnu-1.12.2.tgz", + "integrity": "sha512-q7xRvVpmcfeL+LlZg8Pbbo6QaTZwDU5BaGZbwfhkEsXJn3Was8xYfE0RBH266xZt0rM6B7i8xAYIvjthuUIWHg==", "cpu": [ "ppc64" ], @@ -2052,9 +2086,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-riscv64-gnu": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-riscv64-gnu/-/resolver-binding-linux-riscv64-gnu-1.11.1.tgz", - "integrity": "sha512-frxL4OrzOWVVsOc96+V3aqTIQl1O2TjgExV4EKgRY09AJ9leZpEg8Ak9phadbuX0BA4k8U5qtvMSQQGGmaJqcQ==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-riscv64-gnu/-/resolver-binding-linux-riscv64-gnu-1.12.2.tgz", + "integrity": "sha512-0CVdx6lcnT3Q9inOH8tsMIOJ6ImndllMjqJHg8RLVdB7Vq4SfkEXl9mCSsVNuNA4MCYycRicCUxPCabVHJRr6A==", "cpu": [ "riscv64" ], @@ -2066,9 +2100,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-riscv64-musl": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-riscv64-musl/-/resolver-binding-linux-riscv64-musl-1.11.1.tgz", - "integrity": "sha512-mJ5vuDaIZ+l/acv01sHoXfpnyrNKOk/3aDoEdLO/Xtn9HuZlDD6jKxHlkN8ZhWyLJsRBxfv9GYM2utQ1SChKew==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-riscv64-musl/-/resolver-binding-linux-riscv64-musl-1.12.2.tgz", + "integrity": "sha512-iOwlRo9vnp6R6ohHQS11n0NnfdXx/omhkocmIfaPRpQhKZ+3BDMkkdRVh53qjkFkpPddf+FETA28NwGN7l5l+w==", "cpu": [ "riscv64" ], @@ -2080,9 +2114,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-s390x-gnu": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-s390x-gnu/-/resolver-binding-linux-s390x-gnu-1.11.1.tgz", - "integrity": "sha512-kELo8ebBVtb9sA7rMe1Cph4QHreByhaZ2QEADd9NzIQsYNQpt9UkM9iqr2lhGr5afh885d/cB5QeTXSbZHTYPg==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-s390x-gnu/-/resolver-binding-linux-s390x-gnu-1.12.2.tgz", + "integrity": "sha512-HYJtLfXq94q8iZNFT1lknx258wlkkWhZeUXJRqzKBBUJ00CvZ+N33zgbCqimLjsyw5Va6uUxhVa12mI+kaveEw==", "cpu": [ "s390x" ], @@ -2094,9 +2128,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-x64-gnu": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-x64-gnu/-/resolver-binding-linux-x64-gnu-1.11.1.tgz", - "integrity": "sha512-C3ZAHugKgovV5YvAMsxhq0gtXuwESUKc5MhEtjBpLoHPLYM+iuwSj3lflFwK3DPm68660rZ7G8BMcwSro7hD5w==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-x64-gnu/-/resolver-binding-linux-x64-gnu-1.12.2.tgz", + "integrity": "sha512-mPsUhunKKDih5O96Y6enDQyHc1SqBPlY1E/SfMWDM3EdJ95Z9CArPeCVwCCqbP45ljvivdEk8Fxn+SIb1rDAJQ==", "cpu": [ "x64" ], @@ -2108,9 +2142,9 @@ ] }, "node_modules/@unrs/resolver-binding-linux-x64-musl": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-x64-musl/-/resolver-binding-linux-x64-musl-1.11.1.tgz", - "integrity": "sha512-rV0YSoyhK2nZ4vEswT/QwqzqQXw5I6CjoaYMOX0TqBlWhojUf8P94mvI7nuJTeaCkkds3QE4+zS8Ko+GdXuZtA==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-linux-x64-musl/-/resolver-binding-linux-x64-musl-1.12.2.tgz", + "integrity": "sha512-azrt6+5ydLd8Vt210AAFis/lZevSfPw93EJRIJG+xPu4WCJ8K0kppCTpMyLPcKT7H15M4Jnt2tMp5bOvCkRC6A==", "cpu": [ "x64" ], @@ -2121,10 +2155,24 @@ "linux" ] }, + "node_modules/@unrs/resolver-binding-openharmony-arm64": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-openharmony-arm64/-/resolver-binding-openharmony-arm64-1.12.2.tgz", + "integrity": "sha512-YZ9hP4O0X9PQb8eO980qmLNGH4zT3I9+SZTdt0Pr0YyuGQhYKoOZkV02VzrzyOZJ5xIJ3UFIenKkUkGg8GjgWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, "node_modules/@unrs/resolver-binding-wasm32-wasi": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-wasm32-wasi/-/resolver-binding-wasm32-wasi-1.11.1.tgz", - "integrity": "sha512-5u4RkfxJm+Ng7IWgkzi3qrFOvLvQYnPBmjmZQ8+szTK/b31fQCnleNl1GgEt7nIsZRIf5PLhPwT0WM+q45x/UQ==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-wasm32-wasi/-/resolver-binding-wasm32-wasi-1.12.2.tgz", + "integrity": "sha512-tYFDIkMxSflfEc/h92ZWNsZlHSwgimbNHSO3PL2JWQHfCuC2q316jMyYU9TIWZsFK2bQwyK5VAdYgn8ygPj69A==", "cpu": [ "wasm32" ], @@ -2132,16 +2180,18 @@ "license": "MIT", "optional": true, "dependencies": { - "@napi-rs/wasm-runtime": "^0.2.11" + "@emnapi/core": "1.10.0", + "@emnapi/runtime": "1.10.0", + "@napi-rs/wasm-runtime": "^1.1.4" }, "engines": { "node": ">=14.0.0" } }, "node_modules/@unrs/resolver-binding-win32-arm64-msvc": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-arm64-msvc/-/resolver-binding-win32-arm64-msvc-1.11.1.tgz", - "integrity": "sha512-nRcz5Il4ln0kMhfL8S3hLkxI85BXs3o8EYoattsJNdsX4YUU89iOkVn7g0VHSRxFuVMdM4Q1jEpIId1Ihim/Uw==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-arm64-msvc/-/resolver-binding-win32-arm64-msvc-1.12.2.tgz", + "integrity": "sha512-qzNyg3xL0VPQmCaUh+N5jSitce6k+uCBfMDesWRnlULOZaqUkaJ0ybdT+UqlAWJoQjuqfIU/0Ptx9bteN4D82g==", "cpu": [ "arm64" ], @@ -2153,9 +2203,9 @@ ] }, "node_modules/@unrs/resolver-binding-win32-ia32-msvc": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-ia32-msvc/-/resolver-binding-win32-ia32-msvc-1.11.1.tgz", - "integrity": "sha512-DCEI6t5i1NmAZp6pFonpD5m7i6aFrpofcp4LA2i8IIq60Jyo28hamKBxNrZcyOwVOZkgsRp9O2sXWBWP8MnvIQ==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-ia32-msvc/-/resolver-binding-win32-ia32-msvc-1.12.2.tgz", + "integrity": "sha512-WD9sY00OfpHVGfsnHZoA8jVT+esS/Bg8z8jzxp5BnDCjjwsuKsPQrzswwpFy4J1AUJbXPRfkpcX0mXrzeXW79g==", "cpu": [ "ia32" ], @@ -2167,9 +2217,9 @@ ] }, "node_modules/@unrs/resolver-binding-win32-x64-msvc": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-x64-msvc/-/resolver-binding-win32-x64-msvc-1.11.1.tgz", - "integrity": "sha512-lrW200hZdbfRtztbygyaq/6jP6AKE8qQN2KvPcJ+x7wiD038YtnYtZ82IMNJ69GJibV7bwL3y9FgK+5w/pYt6g==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-x64-msvc/-/resolver-binding-win32-x64-msvc-1.12.2.tgz", + "integrity": "sha512-nAB74NfSNKknqQ1RrYj6uz8FcXEomu/MATJZxh/x+BArzN2U3JbOYC0APYzUIGhVY3m5hRxA8VPNdPBoG8txlA==", "cpu": [ "x64" ], @@ -2436,9 +2486,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.10.29", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.29.tgz", - "integrity": "sha512-Asa2krT+XTPZINCS+2QcyS8WTkObE77RwkydwF7h6DmnKqbvlalz93m/dnphUyCa6SWSP51VgtEUf2FN+gelFQ==", + "version": "2.10.31", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.31.tgz", + "integrity": "sha512-MujYO3eP72uvmSE0i4wltsodRfIpZATP3jvzRNRGGxgzId7aVocVJJV3nf01qnzzKFGxQVC9bpWxl5cjxTr/7Q==", "dev": true, "license": "Apache-2.0", "bin": { @@ -2665,9 +2715,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001792", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001792.tgz", - "integrity": "sha512-hVLMUZFgR4JJ6ACt1uEESvQN1/dBVqPAKY0hgrV70eN3391K6juAfTjKZLKvOMsx8PxA7gsY1/tLMMTcfFLLpw==", + "version": "1.0.30001793", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001793.tgz", + "integrity": "sha512-iwSsYWaCOoh26cV8NwNRViHlrfUvYsHDfRVcbtmw0Kg6PJIZZXwMkj1442FYLBGkeUf1juAsU3DTfxW579mrPA==", "dev": true, "funding": [ { @@ -3052,9 +3102,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.355", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.355.tgz", - "integrity": "sha512-LUPZhKzZPYSPme1jEYohpkA+ybYCJztr1quAdBd7E7h3+VOBVcKkwwtBJu41nrjawrRzfb8mtMfzWozoaK0ZIQ==", + "version": "1.5.361", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.361.tgz", + "integrity": "sha512-Q6Hts7N9FnJc5LeGRINFvLhCI9xZmNtTDe5ZbcVezQz7cU4a8Aua3GH1b8J2XY8Al9PF+OCwYqhgsOOheMdvkA==", "dev": true, "license": "ISC" }, @@ -5362,11 +5412,14 @@ "license": "MIT" }, "node_modules/node-releases": { - "version": "2.0.44", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.44.tgz", - "integrity": "sha512-5WUyunoPMsvvEhS8AxHtRzP+oA8UCkJ7YRxatWKjngndhDGLiqEVAQKWjFAiAiuL8zMRGzGSJxFnLetoa43qGQ==", + "version": "2.0.46", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.46.tgz", + "integrity": "sha512-GYVXHE2KnrzAfsAjl4uP++evGFCrAU1jta4ubEjIG7YWt/64Gqv66a30yKwWczVjA6j3bM4nBwH7Pk1JmDHaxQ==", "dev": true, - "license": "MIT" + "license": "MIT", + "engines": { + "node": ">=18" + } }, "node_modules/normalize-path": { "version": "3.0.0", @@ -6196,9 +6249,9 @@ "license": "MIT" }, "node_modules/qs": { - "version": "6.15.1", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.1.tgz", - "integrity": "sha512-6YHEFRL9mfgcAvql/XhwTvf5jKcOiiupt2FiJxHkiX1z4j7WL8J/jRHYLluORvc1XxB5rV20KoeK00gVJamspg==", + "version": "6.15.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.15.2.tgz", + "integrity": "sha512-Rzq0KEyX/w/tEybncDgdkZrJgVUsUMk3xjh3t5bv3S1HTAtg+uOYt72+ZfwiQwKdysThkTBdL/rTi6HDmX9Ddw==", "license": "BSD-3-Clause", "dependencies": { "side-channel": "^1.1.0" @@ -6426,9 +6479,9 @@ "license": "ISC" }, "node_modules/semver": { - "version": "7.8.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.0.tgz", - "integrity": "sha512-AcM7dV/5ul4EekoQ29Agm5vri8JNqRyj39o0qpX6vDF2GZrtutZl5RwgD1XnZjiTAfncsJhMI48QQH3sN87YNA==", + "version": "7.8.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.1.tgz", + "integrity": "sha512-rkVq3IXh+4FDGch+KwzX3aV9W3kO54GyEgpvBzSyctDA6Xtd7RJQV1xmXbeQp5v7+VzLOfVqiutSE6GICgPFvg==", "dev": true, "license": "ISC", "bin": { @@ -7018,38 +7071,41 @@ "license": "MIT" }, "node_modules/unrs-resolver": { - "version": "1.11.1", - "resolved": "https://registry.npmjs.org/unrs-resolver/-/unrs-resolver-1.11.1.tgz", - "integrity": "sha512-bSjt9pjaEBnNiGgc9rUiHGKv5l4/TGzDmYw3RhnkJGtLhbnnA/5qJj7x3dNDCRx/PJxu774LlH8lCOlB4hEfKg==", + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/unrs-resolver/-/unrs-resolver-1.12.2.tgz", + "integrity": "sha512-dmlRxBJJayXjqTwC+JtF1HhJmgf3ftQ3YejFcZrf4+KKtJv0qDsK1pjqaaVjG7wJ5NJ6UVP1OqRMQ71Z4C3rxQ==", "dev": true, "hasInstallScript": true, "license": "MIT", "dependencies": { - "napi-postinstall": "^0.3.0" + "napi-postinstall": "^0.3.4" }, "funding": { "url": "https://opencollective.com/unrs-resolver" }, "optionalDependencies": { - "@unrs/resolver-binding-android-arm-eabi": "1.11.1", - "@unrs/resolver-binding-android-arm64": "1.11.1", - "@unrs/resolver-binding-darwin-arm64": "1.11.1", - "@unrs/resolver-binding-darwin-x64": "1.11.1", - "@unrs/resolver-binding-freebsd-x64": "1.11.1", - "@unrs/resolver-binding-linux-arm-gnueabihf": "1.11.1", - "@unrs/resolver-binding-linux-arm-musleabihf": "1.11.1", - "@unrs/resolver-binding-linux-arm64-gnu": "1.11.1", - "@unrs/resolver-binding-linux-arm64-musl": "1.11.1", - "@unrs/resolver-binding-linux-ppc64-gnu": "1.11.1", - "@unrs/resolver-binding-linux-riscv64-gnu": "1.11.1", - "@unrs/resolver-binding-linux-riscv64-musl": "1.11.1", - "@unrs/resolver-binding-linux-s390x-gnu": "1.11.1", - "@unrs/resolver-binding-linux-x64-gnu": "1.11.1", - "@unrs/resolver-binding-linux-x64-musl": "1.11.1", - "@unrs/resolver-binding-wasm32-wasi": "1.11.1", - "@unrs/resolver-binding-win32-arm64-msvc": "1.11.1", - "@unrs/resolver-binding-win32-ia32-msvc": "1.11.1", - "@unrs/resolver-binding-win32-x64-msvc": "1.11.1" + "@unrs/resolver-binding-android-arm-eabi": "1.12.2", + "@unrs/resolver-binding-android-arm64": "1.12.2", + "@unrs/resolver-binding-darwin-arm64": "1.12.2", + "@unrs/resolver-binding-darwin-x64": "1.12.2", + "@unrs/resolver-binding-freebsd-x64": "1.12.2", + "@unrs/resolver-binding-linux-arm-gnueabihf": "1.12.2", + "@unrs/resolver-binding-linux-arm-musleabihf": "1.12.2", + "@unrs/resolver-binding-linux-arm64-gnu": "1.12.2", + "@unrs/resolver-binding-linux-arm64-musl": "1.12.2", + "@unrs/resolver-binding-linux-loong64-gnu": "1.12.2", + "@unrs/resolver-binding-linux-loong64-musl": "1.12.2", + "@unrs/resolver-binding-linux-ppc64-gnu": "1.12.2", + "@unrs/resolver-binding-linux-riscv64-gnu": "1.12.2", + "@unrs/resolver-binding-linux-riscv64-musl": "1.12.2", + "@unrs/resolver-binding-linux-s390x-gnu": "1.12.2", + "@unrs/resolver-binding-linux-x64-gnu": "1.12.2", + "@unrs/resolver-binding-linux-x64-musl": "1.12.2", + "@unrs/resolver-binding-openharmony-arm64": "1.12.2", + "@unrs/resolver-binding-wasm32-wasi": "1.12.2", + "@unrs/resolver-binding-win32-arm64-msvc": "1.12.2", + "@unrs/resolver-binding-win32-ia32-msvc": "1.12.2", + "@unrs/resolver-binding-win32-x64-msvc": "1.12.2" } }, "node_modules/update-browserslist-db": { diff --git a/package.json b/package.json index baa3cb5..8448f7b 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "scripts": { "test": "jest", "lint": "eslint src/**/*.ts", - "format": "prettier src --check --write && eslint src/**/*.ts --fix", + "format": "prettier src --write && eslint src/**/*.ts --fix", "build": "npm run build:esm && npm run build:cjs && npm run build:package-markers", "build:esm": "tsc -p tsconfig.json", "build:cjs": "tsc -p tsconfig.cjs.json", diff --git a/src/codeSamples/balancesCodeSamples.test.ts b/src/codeSamples/balancesCodeSamples.test.ts new file mode 100644 index 0000000..ef2cb93 --- /dev/null +++ b/src/codeSamples/balancesCodeSamples.test.ts @@ -0,0 +1,61 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Balances Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/balances'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { balances: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + await client.balances.list({ + creditor: 'CR123', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/bank_account_detailsCodeSamples.test.ts b/src/codeSamples/bank_account_detailsCodeSamples.test.ts new file mode 100644 index 0000000..9d93dd8 --- /dev/null +++ b/src/codeSamples/bank_account_detailsCodeSamples.test.ts @@ -0,0 +1,61 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BankAccountDetails Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_account_details/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_account_details: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.bankAccountDetails.find('BA123', { + 'Gc-Key-Id': 'PK123', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/bank_account_holder_verificationsCodeSamples.test.ts b/src/codeSamples/bank_account_holder_verificationsCodeSamples.test.ts new file mode 100644 index 0000000..84ba1ce --- /dev/null +++ b/src/codeSamples/bank_account_holder_verificationsCodeSamples.test.ts @@ -0,0 +1,89 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BankAccountHolderVerifications Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_account_holder_verifications'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_account_holder_verifications: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const verification = await client.bankAccountHolderVerifications.create({ + type: 'confirmation_of_payee', + links: { + bank_account: 'BA123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_account_holder_verifications/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_account_holder_verifications: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.bankAccountHolderVerifications.find('BAHV123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/bank_authorisationsCodeSamples.test.ts b/src/codeSamples/bank_authorisationsCodeSamples.test.ts new file mode 100644 index 0000000..12a8d6c --- /dev/null +++ b/src/codeSamples/bank_authorisationsCodeSamples.test.ts @@ -0,0 +1,89 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BankAuthorisations Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_authorisations'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const bankAuthorisation = await client.bankAuthorisations.create({ + redirect_uri: 'https://my-company.com/landing', + links: { + billing_request: 'BRQ123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_authorisations/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.bankAuthorisations.find('BAU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/bank_details_lookupsCodeSamples.test.ts b/src/codeSamples/bank_details_lookupsCodeSamples.test.ts new file mode 100644 index 0000000..da2ddbf --- /dev/null +++ b/src/codeSamples/bank_details_lookupsCodeSamples.test.ts @@ -0,0 +1,63 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BankDetailsLookups Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/bank_details_lookups'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { bank_details_lookups: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const bankDetailsLookup = await client.bankDetailsLookups.create({ + account_number: '55779911', + branch_code: '200000', + country_code: 'GB', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/billing_request_flowsCodeSamples.test.ts b/src/codeSamples/billing_request_flowsCodeSamples.test.ts new file mode 100644 index 0000000..6432a82 --- /dev/null +++ b/src/codeSamples/billing_request_flowsCodeSamples.test.ts @@ -0,0 +1,95 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BillingRequestFlows Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_flows'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_flows: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequestFlow = await client.billingRequestFlows.create({ + redirect_uri: 'https://my-company.com/landing', + exit_uri: 'https://my-company.com/exit', + prefilled_customer: { + given_name: 'Frank', + family_name: 'Osborne', + email: 'frank.osborne@acmeplc.com', + }, + links: { + billing_request: 'BRQ123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('initialise code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_flows/:identity/actions/initialise'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_flows: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequestFlows.initialise('BRF123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/billing_request_templatesCodeSamples.test.ts b/src/codeSamples/billing_request_templatesCodeSamples.test.ts new file mode 100644 index 0000000..ffe1048 --- /dev/null +++ b/src/codeSamples/billing_request_templatesCodeSamples.test.ts @@ -0,0 +1,145 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BillingRequestTemplates Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_templates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_templates: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequestTemplates = await client.billingRequestTemplates.list(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_templates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_templates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequestTemplates.find('BRT123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_templates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_templates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequestTemplate = await client.billingRequestTemplates.create({ + name: '12 Month Gold Plan', + payment_request_description: 'One-time joining fee', + mandate_request_description: 'Recurring fee', + payment_request_currency: 'GBP', + payment_request_amount: '69.99', + mandate_request_currency: 'GBP', + redirect_uri: 'https://my-company.com/landing', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_request_templates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_request_templates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequestTemplate = await client.billingRequestTemplates.update('BRT123', { + name: '12 Month Silver Plan', + payment_request_amount: '49.99', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/billing_request_with_actionsCodeSamples.test.ts b/src/codeSamples/billing_request_with_actionsCodeSamples.test.ts new file mode 100644 index 0000000..8df196a --- /dev/null +++ b/src/codeSamples/billing_request_with_actionsCodeSamples.test.ts @@ -0,0 +1,11 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// No code samples exist for BillingRequestWithActions in the schema. + +describe.skip('BillingRequestWithActions Code Samples', () => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + test.skip('no code samples in schema', () => {}); +}); diff --git a/src/codeSamples/billing_requestsCodeSamples.test.ts b/src/codeSamples/billing_requestsCodeSamples.test.ts new file mode 100644 index 0000000..77c074d --- /dev/null +++ b/src/codeSamples/billing_requestsCodeSamples.test.ts @@ -0,0 +1,285 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('BillingRequests Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequest = await client.billingRequests.create({ + payment_request: { + description: 'First Payment', + amount: '500', + currency: 'GBP', + }, + mandate_request: { + scheme: 'bacs', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('collect_customer_details code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/collect_customer_details'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.collectCustomerDetails('BR123', { + customer: { + email: 'alice@example.com', + given_name: 'Alice', + family_name: 'Smith', + }, + customer_billing_detail: { + address_line1: '1 Somewhere Lane', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('collect_bank_account code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/collect_bank_account'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.collectBankAccount('BR123', { + account_number: '55779911', + branch_code: '200000', + account_holder_name: 'Frank Osborne', + country_code: 'GB', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('confirm_payer_details code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/confirm_payer_details'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.confirmPayerDetails('BR123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('fulfil code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/fulfil'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.fulfil('BR123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.cancel('BR123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const billingRequests = await client.billingRequests.list(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.find('BR123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('notify code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/actions/notify'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { billing_requests: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.billingRequests.notify('BR123', { + notification_type: 'email', + redirect_uri: 'https://my-company.com', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/blocksCodeSamples.test.ts b/src/codeSamples/blocksCodeSamples.test.ts new file mode 100644 index 0000000..36235cb --- /dev/null +++ b/src/codeSamples/blocksCodeSamples.test.ts @@ -0,0 +1,196 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Blocks Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const block = await client.blocks.create({ + block_type: Types.BlockBlockType.Email, + resource_reference: 'CU123', + reason_type: Types.BlockReasonType.NoIntentToPay, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const block = await client.blocks.find('BLC456'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + for await (const block of client.blocks.all({})) { + console.log(block.id); + console.log(block.block_type); + } + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('disable code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks/:identity/actions/disable'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const block = await client.blocks.disable('BLC456'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('enable code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks/:identity/actions/enable'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const block = await client.blocks.enable('BLC456'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('block_by_ref code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/blocks/block_by_ref'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { blocks: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const response = await client.blocks.block_by_ref({ + reference_type: Types.BlockReferenceType.Customer, + reference_value: 'CU123', + reason_type: Types.BlockReasonType.NoIntentToPay, + }); + const blocks = response.blocks; + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/creditor_bank_accountsCodeSamples.test.ts b/src/codeSamples/creditor_bank_accountsCodeSamples.test.ts new file mode 100644 index 0000000..a3baf84 --- /dev/null +++ b/src/codeSamples/creditor_bank_accountsCodeSamples.test.ts @@ -0,0 +1,145 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('CreditorBankAccounts Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditor_bank_accounts'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditor_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditorBankAccount = await client.creditorBankAccounts.create({ + account_number: '55779911', + branch_code: '200000', + country_code: 'GB', + account_holder_name: 'Acme', + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditor_bank_accounts'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditor_bank_accounts: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditorBankAccounts = await client.creditorBankAccounts.list(); + + // List all 'enabled' creditor bank accounts. + const enabledCreditorBankAccounts = await client.creditorBankAccounts.list({ enabled: true }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditor_bank_accounts/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditor_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditorBankAccount = await client.creditorBankAccounts.find('BA123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('disable code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditor_bank_accounts/:identity/actions/disable'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditor_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditorBankAccountResponse = await client.creditorBankAccounts.disable('BA123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/creditorsCodeSamples.test.ts b/src/codeSamples/creditorsCodeSamples.test.ts new file mode 100644 index 0000000..6369e05 --- /dev/null +++ b/src/codeSamples/creditorsCodeSamples.test.ts @@ -0,0 +1,146 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Creditors Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditors'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditors: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditor = await client.creditors.create({ + name: 'Acme', + country_code: 'GB', + creditor_type: 'company', + bank_reference_prefix: 'ACME', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditors'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditors: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditors = await client.creditors.list(); + + // List the first three creditors. + const limitedCreditors = await client.creditors.list({ limit: '3' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditors/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditors: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditor = await client.creditors.find('CR123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/creditors/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { creditors: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const creditor = await client.creditors.update('CR123', { + links: { + default_gbp_payout_account: 'BA789', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/currency_exchange_ratesCodeSamples.test.ts b/src/codeSamples/currency_exchange_ratesCodeSamples.test.ts new file mode 100644 index 0000000..27f9022 --- /dev/null +++ b/src/codeSamples/currency_exchange_ratesCodeSamples.test.ts @@ -0,0 +1,62 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('CurrencyExchangeRates Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/currency_exchange_rates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { currency_exchange_rates: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const currencyExchangeRates = await client.currencyExchangeRates.list(); + + // List the currency exchange rate for a source and target currency. + const filteredRates = await client.currencyExchangeRates.list({ source: 'EUR', target: 'GBP' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/customer_bank_accountsCodeSamples.test.ts b/src/codeSamples/customer_bank_accountsCodeSamples.test.ts new file mode 100644 index 0000000..a5f0fba --- /dev/null +++ b/src/codeSamples/customer_bank_accountsCodeSamples.test.ts @@ -0,0 +1,174 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('CustomerBankAccounts Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_bank_accounts'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerBankAccount = await client.customerBankAccounts.create({ + account_number: '55779911', + branch_code: '200000', + account_holder_name: 'Frank Osborne', + country_code: 'GB', + links: { + customer: 'CU123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_bank_accounts'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_bank_accounts: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerBankAccount = await client.customerBankAccounts.list(); + + // List all 'enabled' customer bank accounts. + await client.customerBankAccounts.list({ enabled: true }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_bank_accounts/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerBankAccount = await client.customerBankAccounts.find('BA123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_bank_accounts/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerBankAccount = await client.customerBankAccounts.update('BA123', { + metadata: { + key: 'value', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('disable code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_bank_accounts/:identity/actions/disable'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_bank_accounts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerBankAccount = await client.customerBankAccounts.disable('BA123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/customer_notificationsCodeSamples.test.ts b/src/codeSamples/customer_notificationsCodeSamples.test.ts new file mode 100644 index 0000000..43f1b87 --- /dev/null +++ b/src/codeSamples/customer_notificationsCodeSamples.test.ts @@ -0,0 +1,59 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('CustomerNotifications Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('handle code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customer_notifications/:identity/actions/handle'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customer_notifications: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customerNotification = await client.customerNotifications.handle('PCN123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/customersCodeSamples.test.ts b/src/codeSamples/customersCodeSamples.test.ts new file mode 100644 index 0000000..d6f73ae --- /dev/null +++ b/src/codeSamples/customersCodeSamples.test.ts @@ -0,0 +1,176 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Customers Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customers'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customer = await client.customers.create({ + email: 'user@example.com', + given_name: 'Frank', + family_name: 'Osborne', + address_line1: '27 Acer Road', + address_line2: 'Apt 2', + city: 'London', + postal_code: 'E8 3GX', + country_code: 'GB', + metadata: { + salesforce_id: 'ABCD1234', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customers'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customers: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customer = await client.customers.list(); + + // List customers with a given currency. + await client.customers.list({ currency: 'GBP' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customers/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customer = await client.customers.find('CU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customers/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customer = await client.customers.update('CU123', { + email: 'updated_user@example.com', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('remove code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/customers/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { customers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').delete(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const customer = await client.customers.remove('CU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/eventsCodeSamples.test.ts b/src/codeSamples/eventsCodeSamples.test.ts new file mode 100644 index 0000000..e5fe66a --- /dev/null +++ b/src/codeSamples/eventsCodeSamples.test.ts @@ -0,0 +1,87 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Events Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/events'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { events: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const events = await client.events.list(); + + // List all events of a given resource type. + const paymentEvents = await client.events.list({ resource_type: 'payments' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/events/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { events: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const event = await client.events.find('EV123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/exportsCodeSamples.test.ts b/src/codeSamples/exportsCodeSamples.test.ts new file mode 100644 index 0000000..be17d1b --- /dev/null +++ b/src/codeSamples/exportsCodeSamples.test.ts @@ -0,0 +1,84 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Exports Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/exports/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { exports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const exportData = await client.exports.find('EX123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/exports'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { exports: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const exports = await client.exports.list(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/funds_availabilitiesCodeSamples.test.ts b/src/codeSamples/funds_availabilitiesCodeSamples.test.ts new file mode 100644 index 0000000..f75a645 --- /dev/null +++ b/src/codeSamples/funds_availabilitiesCodeSamples.test.ts @@ -0,0 +1,61 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('FundsAvailabilities Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('check code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/funds_availability/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { funds_availability: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.fundsAvailabilities.check('MD123', { + amount: '1000', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/instalment_schedulesCodeSamples.test.ts b/src/codeSamples/instalment_schedulesCodeSamples.test.ts new file mode 100644 index 0000000..3e03138 --- /dev/null +++ b/src/codeSamples/instalment_schedulesCodeSamples.test.ts @@ -0,0 +1,236 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('InstalmentSchedules Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create_with_dates code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentSchedule = await client.instalmentSchedules.createWithDates( + { + name: 'ACME Invoice 103', + total_amount: '10000', // 100 GBP in pence + app_fee: '10', // Your 10 pence fee per instalment + currency: 'GBP', + instalments: [ + { + charge_date: '2019-08-20', + amount: '3400', + }, + { + charge_date: '2019-09-03', + amount: '3400', + }, + { + charge_date: '2019-09-17', + amount: '3200', + }, + ], + links: { + mandate: 'MD0000XH9A3T4C', + }, + metadata: {}, + }, + 'instalment_schedule_idempotency_key', + ); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('create_with_schedule code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentSchedule = await client.instalmentSchedules.createWithSchedule( + { + name: 'ACME Invoice 103', + total_amount: '10000', // 100 GBP in pence, collected from the customer + app_fee: '10', // Your 10 pence fee, applied to each instalment, + // to be paid out to you + currency: 'GBP', + instalments: { + start_date: '2019-08-20', + interval_unit: 'weekly', + interval: 2, + amounts: ['3400', '3400', '3200'], + }, + links: { + mandate: 'MD0000XH9A3T4C', + }, + metadata: {}, + }, + 'instalment_schedule_idempotency_key', + ); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentSchedules = await client.instalmentSchedules.list(); + + // List all instalment schedules associated with a given customer. + const customerInstalmentSchedules = await client.instalmentSchedules.list({ customer: 'CU123' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentSchedule = await client.instalmentSchedules.find('IS123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentSchedule = await client.instalmentSchedules.update('IS123', { + metadata: { + key: 'value', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/instalment_schedules/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { instalment_schedules: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const instalmentScheduleResponse = await client.instalmentSchedules.cancel('IS123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/institutionsCodeSamples.test.ts b/src/codeSamples/institutionsCodeSamples.test.ts new file mode 100644 index 0000000..d919d04 --- /dev/null +++ b/src/codeSamples/institutionsCodeSamples.test.ts @@ -0,0 +1,88 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Institutions Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/institutions'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { institutions: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + // List of all institutions. + const institutions = await client.institutions.list(); + + // List of institutions for a country code. + const gbInstitutions = await client.institutions.list({ country_code: 'GB' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list_for_billing_request code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/billing_requests/:identity/institutions'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { institutions: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const institutions = await client.institutions.list_for_billing_request('BR123', { country_code: 'GB' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/logosCodeSamples.test.ts b/src/codeSamples/logosCodeSamples.test.ts new file mode 100644 index 0000000..30d0bf6 --- /dev/null +++ b/src/codeSamples/logosCodeSamples.test.ts @@ -0,0 +1,64 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Logos Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create_for_creditor code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/branding/logos'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { logos: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const logo = await client.logos.createForCreditor({ + image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAAA', + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/mandate_import_entriesCodeSamples.test.ts b/src/codeSamples/mandate_import_entriesCodeSamples.test.ts new file mode 100644 index 0000000..539cd9d --- /dev/null +++ b/src/codeSamples/mandate_import_entriesCodeSamples.test.ts @@ -0,0 +1,102 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('MandateImportEntries Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_import_entries'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_import_entries: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImportEntry = await client.mandateImportEntries.create({ + links: { + mandate_import: 'IM000010790WX1', + }, + record_identifier: 'bank-file.xml/line-1', + customer: { + company_name: "Jane's widgets", + email: 'jane@janeswidgets.fr', + }, + bank_account: { + account_holder_name: 'Jane Doe', + iban: 'FR14BARC20000055779911', + }, + amendment: { + original_mandate_reference: 'REFNMANDATE', + original_creditor_id: 'FR123OTHERBANK', + original_creditor_name: 'Existing DD Provider', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_import_entries'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_import_entries: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImportEntries = await client.mandateImportEntries.list(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/mandate_importsCodeSamples.test.ts b/src/codeSamples/mandate_importsCodeSamples.test.ts new file mode 100644 index 0000000..5c62afc --- /dev/null +++ b/src/codeSamples/mandate_importsCodeSamples.test.ts @@ -0,0 +1,136 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('MandateImports Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_imports'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImport = await client.mandateImports.create({ + scheme: 'bacs', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_imports/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImport = await client.mandateImports.find('IM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('submit code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_imports/:identity/actions/submit'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImport = await client.mandateImports.submit('IM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_imports/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateImportResponse = await client.mandateImports.cancel('IM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/mandate_pdfsCodeSamples.test.ts b/src/codeSamples/mandate_pdfsCodeSamples.test.ts new file mode 100644 index 0000000..64ea401 --- /dev/null +++ b/src/codeSamples/mandate_pdfsCodeSamples.test.ts @@ -0,0 +1,82 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('MandatePdfs Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandate_pdfs'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandate_pdfs: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + await client.mandatePdfs.create({ + links: { + mandate: 'MD123', + }, + }); + + await client.mandatePdfs.create( + { + links: { + mandate: 'MD123', + }, + }, + 'mandate_pdfs_idempotency_key', + ); + + await client.mandatePdfs.create( + { + account_number: '44779911', + branch_code: '200000', + country_code: 'GB', + }, + '', + { 'Accept-Language': 'fr' }, + ); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/mandatesCodeSamples.test.ts b/src/codeSamples/mandatesCodeSamples.test.ts new file mode 100644 index 0000000..dd5a97c --- /dev/null +++ b/src/codeSamples/mandatesCodeSamples.test.ts @@ -0,0 +1,198 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Mandates Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandate = await client.mandates.create({ + scheme: 'bacs', + metadata: { + contract: 'ABCD1234', + }, + links: { + customer_bank_account: 'BA123', + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandates = await client.mandates.list(); + + // List all mandates associated with a given customer. + const customerMandates = await client.mandates.list({ customer: 'CU123' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandate = await client.mandates.find('MD123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandate = await client.mandates.update('MD123', { + metadata: { key: 'value' }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateResponse = await client.mandates.cancel('MD123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('reinstate code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/mandates/:identity/actions/reinstate'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const mandateResponse = await client.mandates.reinstate('MD123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/negative_balance_limitsCodeSamples.test.ts b/src/codeSamples/negative_balance_limitsCodeSamples.test.ts new file mode 100644 index 0000000..7c74794 --- /dev/null +++ b/src/codeSamples/negative_balance_limitsCodeSamples.test.ts @@ -0,0 +1,62 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('NegativeBalanceLimits Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/negative_balance_limits'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { negative_balance_limits: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + await client.negativeBalanceLimits.list({ + currency: 'GBP', + creditor: 'CR123', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/outbound_payment_import_entriesCodeSamples.test.ts b/src/codeSamples/outbound_payment_import_entriesCodeSamples.test.ts new file mode 100644 index 0000000..8ae385e --- /dev/null +++ b/src/codeSamples/outbound_payment_import_entriesCodeSamples.test.ts @@ -0,0 +1,62 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('OutboundPaymentImportEntries Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payment_import_entries'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payment_import_entries: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPaymentImportEntries.list({ + outbound_payment_import: 'IM123', + limit: '10', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/outbound_payment_importsCodeSamples.test.ts b/src/codeSamples/outbound_payment_importsCodeSamples.test.ts new file mode 100644 index 0000000..cbd127c --- /dev/null +++ b/src/codeSamples/outbound_payment_importsCodeSamples.test.ts @@ -0,0 +1,132 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('OutboundPaymentImports Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payment_imports'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payment_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const outboundPaymentImport = await client.outboundPaymentImports.create({ + entry_items: [ + { + amount: 1000, + scheme: 'faster_payments', + reference: 'Invoice 123', + recipient_bank_account_id: 'BA123', + }, + { + amount: 2000, + scheme: 'faster_payments', + reference: 'Invoice 124', + recipient_bank_account_id: 'BA456', + metadata: { + order_id: 'ORD-789', + }, + }, + ], + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payment_imports/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payment_imports: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPaymentImports.find('IM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payment_imports'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payment_imports: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPaymentImports.list({ + limit: '10', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/outbound_paymentsCodeSamples.test.ts b/src/codeSamples/outbound_paymentsCodeSamples.test.ts new file mode 100644 index 0000000..ed0d663 --- /dev/null +++ b/src/codeSamples/outbound_paymentsCodeSamples.test.ts @@ -0,0 +1,256 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('OutboundPayments Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const outboundPayment = await client.outboundPayments.create({ + amount: 1000, + scheme: 'faster_payments', + description: 'Reward Payment (August 2024)', + reference: 'Invoice 123', + links: { + creditor: 'CR123', + recipient_bank_account: 'BA123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('withdraw code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/withdrawal'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const outboundPayment = await client.outboundPayments.withdraw({ + amount: 5000, + scheme: 'faster_payments', + description: 'Withdraw funds to business account', + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.cancel('OUT123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('approve code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/:identity/actions/approve'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.approve('OUT123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.find('OUT123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.list({ + limit: '10', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.update('OUT123', { + metadata: { + invoice_id: 'INV-1234', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('stats code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/outbound_payments/stats'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { outbound_payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.outboundPayments.stats(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payer_authorisationsCodeSamples.test.ts b/src/codeSamples/payer_authorisationsCodeSamples.test.ts new file mode 100644 index 0000000..bffabfe --- /dev/null +++ b/src/codeSamples/payer_authorisationsCodeSamples.test.ts @@ -0,0 +1,197 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('PayerAuthorisations Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payer_authorisations/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerAuthorisation = await client.payerAuthorisations.find('PAU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payer_authorisations'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerAuthorisation = await client.payerAuthorisations.create({ + customer: { + email: 'mail@example.com', + given_name: 'Name', + family_name: 'Surname', + metadata: { + salesforce_id: 'EFGH5678', + }, + }, + bank_account: { + account_holder_name: 'Name Surname', + branch_code: '200000', + account_number: '55779911', + metadata: {}, + }, + mandate: { + reference: 'XYZ789', + metadata: {}, + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payer_authorisations/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerAuthorisation = await client.payerAuthorisations.update('PA123', { + customer: { + email: 'mail@example.com', + given_name: 'Name', + family_name: 'Surname', + metadata: { + salesforce_id: 'EFGH5678', + }, + }, + bank_account: { + account_holder_name: 'Name Surname', + branch_code: '200000', + account_number: '55779911', + metadata: {}, + }, + mandate: { + reference: 'XYZ789', + metadata: {}, + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('submit code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payer_authorisations/:identity/actions/submit'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerAuthorisation = await client.payerAuthorisations.submit('PAU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('confirm code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payer_authorisations/:identity/actions/confirm'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_authorisations: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerAuthorisation = await client.payerAuthorisations.confirm('PAU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payer_themesCodeSamples.test.ts b/src/codeSamples/payer_themesCodeSamples.test.ts new file mode 100644 index 0000000..cfb0e95 --- /dev/null +++ b/src/codeSamples/payer_themesCodeSamples.test.ts @@ -0,0 +1,67 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('PayerThemes Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create_for_creditor code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/branding/payer_themes'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payer_themes: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payerThemes = await client.payerThemes.createForCreditor({ + header_background_colour: '#BD10E0', + link_text_colour: '#7ED321', + button_background_colour: '#128DAA', + content_box_border_colour: '#BD10E0', + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payment_account_transactionsCodeSamples.test.ts b/src/codeSamples/payment_account_transactionsCodeSamples.test.ts new file mode 100644 index 0000000..ad0b60e --- /dev/null +++ b/src/codeSamples/payment_account_transactionsCodeSamples.test.ts @@ -0,0 +1,87 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('PaymentAccountTransactions Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payment_account_transactions/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payment_account_transactions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.paymentAccountTransactions.find('PATR1234'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payment_accounts/:identity/transactions'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payment_account_transactions: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const resp = await client.paymentAccountTransactions.list('BA12345', { + value_date_from: '2024-01-01', + value_date_to: '2024-01-31', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payment_accountsCodeSamples.test.ts b/src/codeSamples/payment_accountsCodeSamples.test.ts new file mode 100644 index 0000000..9229f8e --- /dev/null +++ b/src/codeSamples/payment_accountsCodeSamples.test.ts @@ -0,0 +1,11 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// No code samples exist for PaymentAccounts in the schema. + +describe.skip('PaymentAccounts Code Samples', () => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + test.skip('no code samples in schema', () => {}); +}); diff --git a/src/codeSamples/paymentsCodeSamples.test.ts b/src/codeSamples/paymentsCodeSamples.test.ts new file mode 100644 index 0000000..577248c --- /dev/null +++ b/src/codeSamples/paymentsCodeSamples.test.ts @@ -0,0 +1,206 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Payments Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payment = await client.payments.create({ + amount: '100', + currency: 'GBP', + charge_date: '2014-05-19', + reference: 'WINEBOX001', + metadata: { + order_dispatch_date: '2014-05-22', + }, + links: { + mandate: 'MD123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payments = await client.payments.list(); + + // List all payments past a certain date. + const filteredPayments = await client.payments.list({ + created_at: { + gt: '2020-01-01T17:01:06.000Z', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payment = await client.payments.find('PM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payment = await client.payments.update('PM123', { + metadata: { + key: 'value', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const paymentResponse = await client.payments.cancel('PM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('retry code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payments/:identity/actions/retry'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payments: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const paymentResponse = await client.payments.retry('PM123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payout_itemsCodeSamples.test.ts b/src/codeSamples/payout_itemsCodeSamples.test.ts new file mode 100644 index 0000000..9f7f1a8 --- /dev/null +++ b/src/codeSamples/payout_itemsCodeSamples.test.ts @@ -0,0 +1,62 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('PayoutItems Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payout_items'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payout_items: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payoutItems = await client.payoutItems.list({ payout: 'P0123' }); + + // List the first three payout items for a payout + const limitedPayoutItems = await client.payoutItems.list({ payout: 'P0123', limit: '3' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/payoutsCodeSamples.test.ts b/src/codeSamples/payoutsCodeSamples.test.ts new file mode 100644 index 0000000..285f202 --- /dev/null +++ b/src/codeSamples/payoutsCodeSamples.test.ts @@ -0,0 +1,116 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Payouts Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payouts'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payouts: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payouts = await client.payouts.list(); + + // List all payouts with a given status. + await client.payouts.list({ status: 'pending' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payouts/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payouts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payout = await client.payouts.find('PO123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/payouts/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { payouts: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const payout = await client.payouts.update('PO123', { + metadata: { + key: 'value', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/redirect_flowsCodeSamples.test.ts b/src/codeSamples/redirect_flowsCodeSamples.test.ts new file mode 100644 index 0000000..6fc32e0 --- /dev/null +++ b/src/codeSamples/redirect_flowsCodeSamples.test.ts @@ -0,0 +1,120 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('RedirectFlows Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/redirect_flows'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { redirect_flows: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const redirectFlow = await client.redirectFlows.create({ + description: 'Wine boxes', + session_token: 'SESS_wSs0uGYMISxzqOBq', + success_redirect_url: 'https://example.com/pay/confirm', + prefilled_customer: { + given_name: 'Frank', + family_name: 'Osborne', + email: 'frank.osborne@acmeplc.com', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/redirect_flows/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { redirect_flows: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const redirectFlow = await client.redirectFlows.find('RE123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('complete code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/redirect_flows/:identity/actions/complete'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { redirect_flows: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const redirectFlowResponse = await client.redirectFlows.complete('RE123', { + session_token: 'SESS_wSs0uGYMISxzqOBq', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/refundsCodeSamples.test.ts b/src/codeSamples/refundsCodeSamples.test.ts new file mode 100644 index 0000000..94727e0 --- /dev/null +++ b/src/codeSamples/refundsCodeSamples.test.ts @@ -0,0 +1,151 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Refunds Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/refunds'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { refunds: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const refund = await client.refunds.create({ + amount: '100', + total_amount_confirmation: '150', + reference: 'Acme refund', + metadata: { + reason: 'late delivery', + }, + links: { + payment: 'PM123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/refunds'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { refunds: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const refunds = await client.refunds.list(); + + // List all refunds associated with a given mandate. + const mandateRefunds = await client.refunds.list({ mandate: 'MD0123' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/refunds/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { refunds: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const refund = await client.refunds.find('RF123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/refunds/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { refunds: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const refund = await client.refunds.update('RF123', { + metadata: { + key: 'value', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/scenario_simulatorsCodeSamples.test.ts b/src/codeSamples/scenario_simulatorsCodeSamples.test.ts new file mode 100644 index 0000000..6d699a3 --- /dev/null +++ b/src/codeSamples/scenario_simulatorsCodeSamples.test.ts @@ -0,0 +1,63 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('ScenarioSimulators Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('run code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/scenario_simulators/:identity/actions/run'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { scenario_simulators: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const response = await client.scenarioSimulators.run('payment_failed', { + links: { + resource: 'PM123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/scheme_identifiersCodeSamples.test.ts b/src/codeSamples/scheme_identifiersCodeSamples.test.ts new file mode 100644 index 0000000..9f21725 --- /dev/null +++ b/src/codeSamples/scheme_identifiersCodeSamples.test.ts @@ -0,0 +1,115 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('SchemeIdentifiers Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/scheme_identifiers'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { scheme_identifiers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const schemeIdentifier = await client.schemeIdentifiers.create({ + scheme: 'bacs', + name: 'The Wine Club', + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/scheme_identifiers'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { scheme_identifiers: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const schemeIdentifierList = await client.schemeIdentifiers.list(); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/scheme_identifiers/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { scheme_identifiers: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const schemeIdentifier = await client.schemeIdentifiers.find('SU123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/subscriptionsCodeSamples.test.ts b/src/codeSamples/subscriptionsCodeSamples.test.ts new file mode 100644 index 0000000..ef79d9d --- /dev/null +++ b/src/codeSamples/subscriptionsCodeSamples.test.ts @@ -0,0 +1,227 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Subscriptions Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscription = await client.subscriptions.create({ + amount: '2500', + currency: 'GBP', + name: 'Monthly Magazine', + interval_unit: 'monthly', + day_of_month: '1', + metadata: { + order_no: 'ABCD1234', + }, + links: { + mandate: 'MA123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscriptions = await client.subscriptions.list(); + + // List all subscriptions associated with a given customer. + const customerSubscriptions = await client.subscriptions.list({ customer: 'CU123' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscription = await client.subscriptions.find('SB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('update code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').put(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscription = await client.subscriptions.update('SB123', { + amount: '42', + name: 'New Name', + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('pause code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions/:identity/actions/pause'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscriptionResponse = await client.subscriptions.pause('SB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('resume code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions/:identity/actions/resume'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscriptionResponse = await client.subscriptions.resume('SB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('cancel code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/subscriptions/:identity/actions/cancel'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { subscriptions: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const subscriptions = await client.subscriptions.cancel('SB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/tax_ratesCodeSamples.test.ts b/src/codeSamples/tax_ratesCodeSamples.test.ts new file mode 100644 index 0000000..311c57f --- /dev/null +++ b/src/codeSamples/tax_ratesCodeSamples.test.ts @@ -0,0 +1,87 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('TaxRates Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/tax_rates'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { tax_rates: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const taxRates = await client.taxRates.list(); + + // List the Tax rate for a jurisdiction. + const taxRatesFiltered = await client.taxRates.list({ jurisdiction: 'GB' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/tax_rates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { tax_rates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const taxRate = await client.taxRates.find('GB_VAT_1'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/transferred_mandatesCodeSamples.test.ts b/src/codeSamples/transferred_mandatesCodeSamples.test.ts new file mode 100644 index 0000000..fd73fbc --- /dev/null +++ b/src/codeSamples/transferred_mandatesCodeSamples.test.ts @@ -0,0 +1,59 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('TransferredMandates Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('transferred_mandates code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/transferred_mandates/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { transferred_mandates: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const transferredMandate = await client.transferredMandates.transferredMandates('MD123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/verification_detailsCodeSamples.test.ts b/src/codeSamples/verification_detailsCodeSamples.test.ts new file mode 100644 index 0000000..e6e62be --- /dev/null +++ b/src/codeSamples/verification_detailsCodeSamples.test.ts @@ -0,0 +1,105 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('VerificationDetails Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('create code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/verification_details'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { verification_details: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const verificationDetail = await client.verificationDetails.create({ + name: 'Acme', + company_number: '03768189', + address_line1: '12 Drury lane', + city: 'London', + description: 'wine and cheese seller', + postal_code: 'B4 7NJ', + directors: [ + { + given_name: 'Gandalf', + family_name: 'Grey', + city: 'London', + date_of_birth: '1986-02-19', + street: 'Drury lane', + postal_code: 'B4 7NJ', + country_code: 'GB', + }, + ], + links: { + creditor: 'CR123', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/verification_details'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { verification_details: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const verificationDetailList = await client.verificationDetails.list({ creditor: 'CR123' }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/codeSamples/webhooksCodeSamples.test.ts b/src/codeSamples/webhooksCodeSamples.test.ts new file mode 100644 index 0000000..a6c40d0 --- /dev/null +++ b/src/codeSamples/webhooksCodeSamples.test.ts @@ -0,0 +1,116 @@ +// WARNING: Do not edit by hand, this file was generated by Crank: +// +// https://github.com/gocardless/crank +// + +// Code Sample Tests +// These tests verify that the documentation code samples are syntactically valid +// and can execute against a mocked API without errors. +// +// IMPORTANT: These tests do NOT verify business logic - they only verify that +// the code samples compile and execute without syntax errors. + +import * as nock from 'nock'; +import { GoCardlessClient } from '../client'; +import { Environments } from '../constants'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +import * as Types from '../types/Types'; + +describe('Webhooks Code Samples', () => { + const token = 'SECRET_TOKEN'; + let client: GoCardlessClient; + + beforeAll(() => { + nock.disableNetConnect(); + }); + + beforeEach(() => { + client = new GoCardlessClient(token, Environments.Live, {}); + }); + + afterEach(() => { + nock.cleanAll(); + }); + + test('list code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/webhooks'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { webhooks: [{}], meta: { cursors: {}, limit: 50 } }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const webhooks = await client.webhooks.list(); + + // List all webhooks past a certain date. + const filteredWebhooks = await client.webhooks.list({ + created_at: { + gt: '2020-01-01T17:01:06.000Z', + }, + }); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('get code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/webhooks/:identity'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { webhooks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').get(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const webhook = await client.webhooks.find('WB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); + + test('retry code sample executes without error', async () => { + // Convert :param placeholders to regex wildcards for flexible matching + const stubUrl = '/webhooks/:identity/actions/retry'; + const pathPattern = new RegExp('^' + stubUrl.replace(/:[\w]+/g, '[^/?]+') + '(?:\\?.*)?$'); + + // Mock response - repeat multiple times to handle code samples with multiple API calls + const responseBody = { webhooks: {} }; + for (let i = 0; i < 5; i++) { + nock('https://api.gocardless.com').post(pathPattern).query(true).reply(200, responseBody); + } + + // Suppress console.log from code samples + const originalLog = console.log; + // eslint-disable-next-line @typescript-eslint/no-empty-function + console.log = () => {}; + + try { + /* eslint-disable @typescript-eslint/no-unused-vars */ + const webhookResponse = await client.webhooks.retry('WB123'); + /* eslint-enable @typescript-eslint/no-unused-vars */ + } finally { + console.log = originalLog; + } + }); +}); diff --git a/src/types/Types.ts b/src/types/Types.ts index 58c7b5b..65911ef 100644 --- a/src/types/Types.ts +++ b/src/types/Types.ts @@ -969,9 +969,7 @@ export type BillingRequestMandateRequestConstraintsPeriodicLimit = { // The maximum number of payments that can be collected in this periodic // limit. - // _Note:_ Only supported for the PayTo scheme, where it is required. - // Providing this field for other VRP schemes will result in a validation - // error. + // _Note:_ This is only supported for the PayTo scheme, where it is required. // max_payments?: number; @@ -1707,9 +1705,7 @@ export type BillingRequestTemplateMandateRequestConstraintsPeriodicLimit = { // The maximum number of payments that can be collected in this periodic // limit. - // _Note:_ Only supported for the PayTo scheme, where it is required. - // Providing this field for other VRP schemes will result in a validation - // error. + // _Note:_ This is only supported for the PayTo scheme, where it is required. // max_payments?: number; @@ -2131,9 +2127,7 @@ export type BillingRequestWithActionMandateRequestConstraintsPeriodicLimit = { // The maximum number of payments that can be collected in this periodic // limit. - // _Note:_ Only supported for the PayTo scheme, where it is required. - // Providing this field for other VRP schemes will result in a validation - // error. + // _Note:_ This is only supported for the PayTo scheme, where it is required. // max_payments?: number; @@ -3097,9 +3091,7 @@ export type BillingRequestWithActionBillingRequestsMandateRequestConstraintsPeri // The maximum number of payments that can be collected in this periodic // limit. - // _Note:_ Only supported for the PayTo scheme, where it is required. - // Providing this field for other VRP schemes will result in a validation - // error. + // _Note:_ This is only supported for the PayTo scheme, where it is required. // max_payments?: number; diff --git a/src/webhooks.ts b/src/webhooks.ts index 1d48a38..730477b 100644 --- a/src/webhooks.ts +++ b/src/webhooks.ts @@ -18,6 +18,11 @@ function InvalidSignatureError() { this.name = 'InvalidSignatureError'; } +interface WebhookParseResult { + events: Event[]; + webhookId: string | null; +} + /** * Validates that a webhook was genuinely sent by GoCardless, then parses each `event` * object into an array of `GoCardless.Event` classes. @@ -36,6 +41,27 @@ function parse(body: crypto.BinaryLike, webhookSecret: string, signatureHeader: return eventsData.events; } +/** + * Validates that a webhook was genuinely sent by GoCardless, then parses it into + * a result object containing both the events and the webhook ID from the meta field. + * + * @body The raw webhook body. + * @webhookSecret The webhook endpoint secret for your webhook endpoint, as + * configured in your GoCardless Dashboard. + * @signatureHeader The signature included in the webhook request, as specified + * by the `Webhook-Signature` header. + */ +function parseWithMeta(body: crypto.BinaryLike, webhookSecret: string, signatureHeader: string): WebhookParseResult { + verifySignature(body, webhookSecret, signatureHeader); + + const bodyString = typeof body === 'string' ? body : body.toString(); + const parsed = JSON.parse(bodyString) as { events: Event[]; meta?: { webhook_id?: string } }; + return { + events: parsed.events, + webhookId: parsed.meta?.webhook_id ?? null, + }; +} + /** * Validate the signature header. Note, we're using the `crypto.timingSafeEqual` * library for the hash comparison, to protect against timing attacks. @@ -58,4 +84,4 @@ function verifySignature(body: crypto.BinaryLike, webhookSecret: string, signatu } } -export { parse, verifySignature, InvalidSignatureError }; +export { parse, parseWithMeta, verifySignature, InvalidSignatureError, WebhookParseResult };