Skip to content

Commit

Permalink
test: add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
owenvoke committed May 30, 2024
1 parent c402205 commit b7c8b67
Show file tree
Hide file tree
Showing 7 changed files with 417 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/api/checkAddress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("Function: checkAddress", () => {
const mockResponse = {
status: "ok",
data: true,
coint: "arionum",
};

let requestUrl = "";
Expand Down Expand Up @@ -55,6 +56,7 @@ describe("Function: checkAddress", () => {
const mockResponse = {
status: "ok",
data: false,
coint: "arionum",
};

let requestUrl = "";
Expand Down
2 changes: 2 additions & 0 deletions src/api/checkSignature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("Function: checkSignature", () => {
const mockResponse = {
status: "ok",
data: true,
coint: "arionum",
};

let requestUrl = "";
Expand Down Expand Up @@ -64,6 +65,7 @@ describe("Function: checkSignature", () => {
const mockResponse = {
status: "ok",
data: false,
coint: "arionum",
};

let requestUrl = "";
Expand Down
84 changes: 84 additions & 0 deletions src/api/getAlias.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";

import { buildNodeConfiguration } from "../utils/public";
import { getAlias } from "./getAlias";

const server = setupServer();

describe("Function: getAlias", () => {
// MSW Setup
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it("returns alias for address", async () => {
// ARRANGE
const nodeConfiguration = buildNodeConfiguration({
url: "http://localhost",
});

const mockResponse = {
status: "ok",
data: "PXGAMER",
coin: "arionum",
};

let requestUrl = "";

server.use(
http.get(`http://localhost/api.php`, (info) => {
requestUrl = info.request.url;
return HttpResponse.json(mockResponse);
}),
);

// ACT
const response = await getAlias(nodeConfiguration, {
address:
"51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J",
});

// ASSERT
expect(requestUrl).toContain(
"account=51sJ4LbdKzhyGy4zJGqodNLse9n9JsVT2rdeH92w7cf3qQuSDJupvjbUT1UBr7r1SCUAXG97saxn7jt2edKb4v4J",
);

expect(response).toEqual("PXGAMER");
});

it("returns alias with public key validation", async () => {
// ARRANGE
const nodeConfiguration = buildNodeConfiguration({
url: "http://localhost",
});

const mockResponse = {
status: "ok",
data: "PXGAMER",
coin: "arionum",
};

let requestUrl = "";

server.use(
http.get(`http://localhost/api.php`, (info) => {
requestUrl = info.request.url;
return HttpResponse.json(mockResponse);
}),
);

// ACT
const response = await getAlias(nodeConfiguration, {
publicKey:
"PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4",
});

// ASSERT
expect(requestUrl).toContain(
"public_key=PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCyk7aKeBJ6LL44w5JGSFp82Wb1Drqicuznv1qmRVQMvbmF64AeczjMtV72acGLR9RsiQ2JccemNrSPkKi8KDk72t4",
);

expect(response).toEqual("PXGAMER");
});
});
2 changes: 1 addition & 1 deletion src/api/getAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { call } from "../utils/internal";

export const getAlias = async (
nodeConfiguration: NodeConfiguration,
payload: { address: string; publicKey?: string },
payload: { address?: string; publicKey?: string },
): Promise<string> => {
const { address, publicKey } = payload;

Expand Down
166 changes: 166 additions & 0 deletions src/api/getAssetBalance.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import { http, HttpResponse } from "msw";
import { setupServer } from "msw/node";

import { buildNodeConfiguration } from "../utils/public";
import { getAssetBalance } from "./getAssetBalance";

const server = setupServer();

describe("Function: getAssetBalance", () => {
// MSW Setup
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

it("returns asset balances for asset", async () => {
// ARRANGE
const nodeConfiguration = buildNodeConfiguration({
url: "http://localhost",
});

const mockResponse = {
status: "ok",
data: [
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
account:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
],
coin: "arionum",
};

let requestUrl = "";

server.use(
http.get(`http://localhost/api.php`, (info) => {
requestUrl = info.request.url;
return HttpResponse.json(mockResponse);
}),
);

// ACT
const response = await getAssetBalance(nodeConfiguration, {
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
});

// ASSERT
expect(requestUrl).toContain(
"asset=63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
);

expect(response).toEqual([
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
address:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
]);
});

it("returns asset balances for account", async () => {
// ARRANGE
const nodeConfiguration = buildNodeConfiguration({
url: "http://localhost",
});

const mockResponse = {
status: "ok",
data: [
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
account:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
],
coin: "arionum",
};

let requestUrl = "";

server.use(
http.get(`http://localhost/api.php`, (info) => {
requestUrl = info.request.url;
return HttpResponse.json(mockResponse);
}),
);

// ACT
const response = await getAssetBalance(nodeConfiguration, {
address:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
});

// ASSERT
expect(requestUrl).toContain(
"account=2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
);

expect(response).toEqual([
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
address:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
]);
});

it("returns asset balances for public key", async () => {
// ARRANGE
const nodeConfiguration = buildNodeConfiguration({
url: "http://localhost",
});

const mockResponse = {
status: "ok",
data: [
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
account:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
],
coin: "arionum",
};

let requestUrl = "";

server.use(
http.get(`http://localhost/api.php`, (info) => {
requestUrl = info.request.url;
return HttpResponse.json(mockResponse);
}),
);

// ACT
const response = await getAssetBalance(nodeConfiguration, {
publicKey:
"PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m",
});

// ASSERT
expect(requestUrl).toContain(
"public_key=PZ8Tyr4Nx8MHsRAGMpZmZ6TWY63dXWSCzZitehhR4qa7Xe2Fz3ZHHb3njMbyKFohQqdPeYvDKdtHzCCgC9Nqs4DwF294Qqqms5HMjMRCkqmpE7qc8nEarC6m",
);

expect(response).toEqual([
{
asset: "63XhfCKHGCDUhwzWgb61nhNY7SD5HTTAV1XZ9fVqPAAe9oGyRtQruojT13A3pmWFEugd99qMDgGbgbQzPCE5ciHE",
alias: "AUOS",
address:
"2MhGjby9kNXNgjViGNqACEASiZMxqT7JQGgiAbYnqG5mZ44AeUbtjRWDusAPKxFLng5ioi6dxyhFzQ33RzoH9SX5",
balance: 1234,
},
]);
});
});
Loading

0 comments on commit b7c8b67

Please sign in to comment.