Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions __tests__/charges/createCharge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { TEST_API_KEY } from "../../src/constants";
import { zbd } from "../../src/zbd";
import {
ChargeDataResponseType,
ChargeOptionsType,
isChargeResponseType,
} from "../../src/types/charges";

const ZBD = new zbd(TEST_API_KEY);

describe("createCharge", () => {
it("should successfully create a charge", async () => {
const payload: ChargeOptionsType = {
expiresIn: 300,
amount: "10000",
description: "My Charge Test Zapier",
internalId: "internalId",
callbackUrl: "https://my-website.com/zbd-callback",
};

const response = await ZBD.createCharge(payload);

expect(isChargeResponseType(response)).toBeTruthy();
expect(response.success).toBe(true);
expect(response.message).toBe("Charge created.");
expect(response.data.amount).toBe(payload.amount);
expect(response.data.description).toBe(payload.description);
});

describe("createCharge error scenarios", () => {
it("should throw an error given an erroneous payload (amount = 0)", async () => {
const erroneousPayload: ChargeOptionsType = {
expiresIn: 100,
amount: "0",
description: "My Charge Test Zapier",
internalId: "internalId",
callbackUrl: "https://my-website.com/zbd-callback",
};

await expect(ZBD.createCharge(erroneousPayload)).rejects.toMatchObject({
message: "Request has missing or mismatch params.",
status: 400,
});
});
});
});
32 changes: 32 additions & 0 deletions __tests__/charges/getCharge.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { zbd } from "@zbd/node";
import { TEST_API_KEY } from "../../src/constants";
import {
ChargeDataResponseType,
isChargeResponseType,
} from "../../src/types/charges";

const ZBD = new zbd(TEST_API_KEY);

describe("getCharge", () => {
const VALID_CHARGE_ID = "4f0fa38f-efbe-485f-9293-95e697f6fbd4";
const INVALID_CHARGE_ID = "invalid";
const INVALID_API_KEY = "INVALID_API_KEY";

// Success
it("should fetch charge details for a valid charge ID", async () => {
const data = await ZBD.getCharge(VALID_CHARGE_ID);
expect(data.success).toBe(true);
expect(data.message).toBe("Fetched Charge.");

// Data Validation
expect(isChargeResponseType(data)).toBeTruthy();
});

// Charge not found
it("should return a 404 for a non-existent charge ID", async () => {
await expect(ZBD.getCharge(INVALID_CHARGE_ID)).rejects.toMatchObject({
message: "No Charge records found with this ID.",
status: 404,
});
});
});
35 changes: 0 additions & 35 deletions __tests__/create-charge.test.ts

This file was deleted.

46 changes: 46 additions & 0 deletions __tests__/gamertag/fetchChargeFromGamertag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { TEST_API_KEY } from "../../src/constants";
import {
FetchChargeFromGamertagDataResponseType,
FetchChargeFromGamertagOptionsType,
isFetchChargeFromGamertagDataResponseType,
} from "../../src/types";
import { zbd } from "../../src/zbd";

const ZBD = new zbd(TEST_API_KEY);

describe("Fetch Charge from Gamertag", () => {
const requestBody: FetchChargeFromGamertagOptionsType = {
amount: "1000",
gamertag: "andre",
description: "Requesting Charge for Gamertag",
callbackUrl: "https://your-website.com/zbd-callback",
internalId: "test-internal-id",
};

it("should successfully create a charge for a gamertag", async () => {
const response = await ZBD.createGamertagCharge(requestBody);

expect(response).toBeDefined();
expect(response.success).toBe(true);
expect(isFetchChargeFromGamertagDataResponseType(response)).toBeTruthy();
});

describe("fetchGamertagByUserID error scenarios", () => {
it("should throw an error given a non-existent user ID", async () => {
const errorRequestBody: FetchChargeFromGamertagOptionsType = {
amount: "1000",
gamertag: "fakeGamerTagĆ",
description: "Requesting Charge for fake Gamertag",
callbackUrl: "https://your-website.com/zbd-callback",
internalId: "test-internal-id",
};

await expect(
ZBD.createGamertagCharge(errorRequestBody)
).rejects.toMatchObject({
message: "API request failed",
status: 500,
});
});
});
});
33 changes: 33 additions & 0 deletions __tests__/gamertag/fetchGamertagByUserID.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { TEST_API_KEY } from "../../src/constants";
import {
FetchGamertagByUserIdDataResponseType,
isFetchGamertagByUserIDDataResponseType,
} from "../../src/types";
import { zbd } from "../../src/zbd";

const ZBD = new zbd(TEST_API_KEY);

describe("Fetch Gamertag By User ID", () => {
const testUserID = "ec9b38d5-b126-4307-9d1e-8aa0dfab5d7e";
const fakeUserID = "202020";

it("should successfully fetch a gamertag by user ID", async () => {
const response = await ZBD.getGamertagByUserId(testUserID);

expect(response).toBeDefined();
expect(response.success).toBe(true);
expect(response.message).toBe("Fetched gamertag from uuid");

// Data Validation
expect(isFetchGamertagByUserIDDataResponseType(response)).toBeTruthy();
});

describe("fetchGamertagByUserID error scenarios", () => {
it("should throw an error given a non-existent user ID", async () => {
await expect(ZBD.getGamertagByUserId(fakeUserID)).rejects.toMatchObject({
message: "No gamertag found with this uuid",
status: 400,
});
});
});
});
34 changes: 34 additions & 0 deletions __tests__/gamertag/fetchGamertagTransactionDetailsByID.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { TEST_API_KEY } from "../../src/constants";
import {
GamertagTransactionDataResponseType,
isGamertagTransactionDataResponseType,
} from "../../src/types";
import { zbd } from "../../src/zbd";

const ZBD = new zbd(TEST_API_KEY);

describe("Fetch Gamertag Transaction Details By ID", () => {
const TEST_TRANSACTION_ID = "3418e871-05f6-4745-b12b-ccd53da9c4d1";
const NON_EXISTENT_TRANSACTION_ID = "903883f2-67d9-4707-a21b-ddff004fe041";

it("should successfully fetch transaction details by ID", async () => {
const response = await ZBD.getGamertagTransaction(TEST_TRANSACTION_ID);

expect(response).toBeDefined();
expect(response.success).toBe(true);

expect(isGamertagTransactionDataResponseType(response)).toBeTruthy();
});

describe("fetchGamertagTransactionDetailsByID error scenarios", () => {
it("should fail to fetch transaction details given false ID", async () => {
const response = await ZBD.getGamertagTransaction(
NON_EXISTENT_TRANSACTION_ID
);

expect(response).toBeDefined();
expect(response.success).toBe(true);
expect(response.message).toBe("Transaction not found");
});
});
});
31 changes: 31 additions & 0 deletions __tests__/gamertag/fetchUserIDFromGamertag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { TEST_API_KEY } from "../../src/constants";
import {
FetchUserIdByGamertagDataResponseType,
isFetchUserIdByGamertagDataResponseType,
} from "../../src/types";
import { zbd } from "../../src/zbd";

const ZBD = new zbd(TEST_API_KEY);

describe("Fetch User ID By Gamertag", () => {
const testGamertag = "foxp2";

it("should successfully fetch user ID for a valid gamertag", async () => {
const response = await ZBD.getUserIdByGamertag(testGamertag);

expect(response).toBeDefined();
expect(response.success).toBe(true);
expect(isFetchUserIdByGamertagDataResponseType(response)).toBeTruthy();
});

it("should return an error for an invalid gamertag", async () => {
const invalidGamertag = "nonExistentTagč";

await expect(
ZBD.getUserIdByGamertag(invalidGamertag)
).rejects.toMatchObject({
message: "No user found with this gamertag",
status: 400,
});
});
});
43 changes: 43 additions & 0 deletions __tests__/gamertag/sendPaymentToGamertag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { TEST_API_KEY } from "../../src/constants";
import {
SendGamertagPaymentOptionsType,
isSendGamertagPaymentDataResponseType,
} from "../../src/types";
import { zbd } from "../../src/zbd";

const ZBD = new zbd(TEST_API_KEY);

describe("Send Payment to Gamertag", () => {
const mockRequestBody: SendGamertagPaymentOptionsType = {
gamertag: "foxp2",
amount: "1000",
description: "Sending to ZBD Gamertag",
};

it("should successfully send payment to a gamertag", async () => {
const response = await ZBD.sendGamertagPayment(mockRequestBody); // Assuming ZBD has a method called sendPaymentToGamertag

expect(response).toBeDefined();
expect(response.success).toBe(true);
expect(response.message).toBe("Payment done.");

expect(isSendGamertagPaymentDataResponseType(response)).toBeTruthy();
});

describe("sendPaymentToGamertag error scenarios", () => {
it("should throw an error given a non-existent gamertag", async () => {
const errorRequestBody: SendGamertagPaymentOptionsType = {
gamertag: "fakeGamertagĆ",
amount: "1000",
description: "Sending to non-existent Gamertag",
};

await expect(
ZBD.sendGamertagPayment(errorRequestBody)
).rejects.toMatchObject({
message: "You cannot pay to this user, missing destination",
status: 500,
});
});
});
});
16 changes: 0 additions & 16 deletions __tests__/get-btcusd.test.ts

This file was deleted.

30 changes: 0 additions & 30 deletions __tests__/get-payment.test.ts

This file was deleted.

16 changes: 0 additions & 16 deletions __tests__/get-wallet.test.ts

This file was deleted.

Loading