diff --git a/package.json b/package.json index 4b45a783b..526ea0157 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "start:check": "turbo run build && turbo run build:watch start types:watch lint:watch --parallel --concurrency 200", "start": "turbo run build && turbo run build:watch start --concurrency 200", "test": "turbo run test", + "test:integration": "turbo run test:integration", "types": "turbo run types" }, "workspaces": [ @@ -41,7 +42,7 @@ "@changesets/cli": "^2.26.1", "@manypkg/cli": "^0.21.0", "ts-prune": "^0.10.3", - "turbo": "v1.10.1", + "turbo": "1.10.15", "unimported": "^1.29.2" }, "packageManager": "yarn@3.6.0" diff --git a/packages/lightspark-sdk/package.json b/packages/lightspark-sdk/package.json index ef724e81d..51be8e2ba 100644 --- a/packages/lightspark-sdk/package.json +++ b/packages/lightspark-sdk/package.json @@ -80,7 +80,9 @@ "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color", "lint": "eslint .", "postversion": "yarn build", - "test": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail", + "test-cmd": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail", + "test": "yarn test-cmd src/tests/*.test.ts", + "test:integration": "yarn test-cmd src/tests/integration/*.test.ts", "types:watch": "tsc-absolute --watch", "types": "tsc" }, diff --git a/packages/lightspark-sdk/src/tests/integration/client.test.ts b/packages/lightspark-sdk/src/tests/integration/client.test.ts new file mode 100644 index 000000000..69d8ef7cc --- /dev/null +++ b/packages/lightspark-sdk/src/tests/integration/client.test.ts @@ -0,0 +1,60 @@ +import LightsparkClient from "../../client.js"; +import { getCredentialsFromEnvOrThrow } from "../../env.js"; +import { + AccountTokenAuthProvider, + BitcoinNetwork, + PaymentRequestStatus, +} from "../../index.js"; + +describe("lightspark-sdk client", () => { + const { apiTokenClientId, apiTokenClientSecret, baseUrl } = + getCredentialsFromEnvOrThrow(); + const accountAuthProvider = new AccountTokenAuthProvider( + apiTokenClientId, + apiTokenClientSecret, + ); + let regtestNodeId: string | undefined; + + function getRegtestNodeId() { + expect(regtestNodeId).toBeDefined(); + if (!regtestNodeId) { + throw new Error("regtestNodeId is not set"); + } + return regtestNodeId as string; + } + + it("should get env vars and construct the client successfully", async () => { + const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl); + expect(lightsparkClient).toBeDefined(); + }); + + it("should successfully get the current account regtest node", async () => { + const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl); + + const account = await lightsparkClient.getCurrentAccount(); + const nodesConnection = await account?.getNodes(lightsparkClient, 1, [ + BitcoinNetwork.REGTEST, + ]); + + const regtestNode = nodesConnection?.entities[0]; + expect(regtestNode).toBeDefined(); + regtestNodeId = regtestNode?.id; + }); + + it("should successfully create an uma invoice", async () => { + const nodeId = getRegtestNodeId(); + const lightsparkClient = new LightsparkClient(accountAuthProvider, baseUrl); + + const metadata = JSON.stringify([ + ["text/plain", "Pay to vasp2.com user $bob"], + ["text/identifier", "$bob@vasp2.com"], + ]); + + const umaInvoice = await lightsparkClient.createUmaInvoice( + nodeId, + 1000, + metadata, + ); + expect(umaInvoice?.status).toEqual(PaymentRequestStatus.OPEN); + }); +}); diff --git a/turbo.json b/turbo.json index 5afa59a8c..0b2a26bd6 100644 --- a/turbo.json +++ b/turbo.json @@ -45,6 +45,9 @@ "test": { "dependsOn": ["^build"] }, + "test:integration": { + "dependsOn": ["^build"] + }, "types": {}, "types:watch": { "cache": false, diff --git a/yarn.lock b/yarn.lock index 88228110e..7eae7da31 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13555,7 +13555,7 @@ __metadata: "@changesets/cli": ^2.26.1 "@manypkg/cli": ^0.21.0 ts-prune: ^0.10.3 - turbo: v1.10.1 + turbo: 1.10.15 unimported: ^1.29.2 languageName: unknown linkType: soft @@ -20016,58 +20016,58 @@ __metadata: languageName: node linkType: hard -"turbo-darwin-64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-darwin-64@npm:1.10.1" +"turbo-darwin-64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-darwin-64@npm:1.10.15" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"turbo-darwin-arm64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-darwin-arm64@npm:1.10.1" +"turbo-darwin-arm64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-darwin-arm64@npm:1.10.15" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"turbo-linux-64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-linux-64@npm:1.10.1" +"turbo-linux-64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-linux-64@npm:1.10.15" conditions: os=linux & cpu=x64 languageName: node linkType: hard -"turbo-linux-arm64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-linux-arm64@npm:1.10.1" +"turbo-linux-arm64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-linux-arm64@npm:1.10.15" conditions: os=linux & cpu=arm64 languageName: node linkType: hard -"turbo-windows-64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-windows-64@npm:1.10.1" +"turbo-windows-64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-windows-64@npm:1.10.15" conditions: os=win32 & cpu=x64 languageName: node linkType: hard -"turbo-windows-arm64@npm:1.10.1": - version: 1.10.1 - resolution: "turbo-windows-arm64@npm:1.10.1" +"turbo-windows-arm64@npm:1.10.15": + version: 1.10.15 + resolution: "turbo-windows-arm64@npm:1.10.15" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"turbo@npm:v1.10.1": - version: 1.10.1 - resolution: "turbo@npm:1.10.1" - dependencies: - turbo-darwin-64: 1.10.1 - turbo-darwin-arm64: 1.10.1 - turbo-linux-64: 1.10.1 - turbo-linux-arm64: 1.10.1 - turbo-windows-64: 1.10.1 - turbo-windows-arm64: 1.10.1 +"turbo@npm:1.10.15": + version: 1.10.15 + resolution: "turbo@npm:1.10.15" + dependencies: + turbo-darwin-64: 1.10.15 + turbo-darwin-arm64: 1.10.15 + turbo-linux-64: 1.10.15 + turbo-linux-arm64: 1.10.15 + turbo-windows-64: 1.10.15 + turbo-windows-arm64: 1.10.15 dependenciesMeta: turbo-darwin-64: optional: true @@ -20083,7 +20083,7 @@ __metadata: optional: true bin: turbo: bin/turbo - checksum: 3551c57be67e833583de549d74d5ec991e0f1e38047e25600b8acc085a1a8a4007992259a015eb9f2c0abd68156545800bd34e7b5ad337d1998b32461952d3fb + checksum: b494c8bf79355874919e76ee0e4a0a53616e0ae5c7126eb1add50e67d4cd1e445ed9aecf99cb6d81c592b7a43ba91cd7dbf30df70410a44cecedba8b5126095d languageName: node linkType: hard