Skip to content
Open
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TESTING_VALORANT_REGION=# "na" | "eu" | "latam" | "br" | "ap" | "kr" | "pbe";
1 change: 1 addition & 0 deletions .github/workflows/update-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:

- name: Cache node modules
uses: actions/cache@v2
id: cache-node-modules
env:
cache-name: cache-node-modules
with:
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn test --coverage && npx istanbul-badges-readme && git add 'README.md'
yarn test:unit --coverage && npx istanbul-badges-readme && git add 'README.md'
11 changes: 11 additions & 0 deletions __tests__/__setup__/integration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ValClient } from "@app/client";

import type { Regions } from "@type/resources";

export const client = new ValClient();

beforeAll(async () => {
if (!client.auth || !client.endpoints.local) {
await client.init({ region: process.env.TESTING_VALORANT_REGION as Regions });
}
});
2 changes: 2 additions & 0 deletions __tests__/__setup__/jest-extended.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "jest-extended";
import "jest-extended/all";
57 changes: 57 additions & 0 deletions __tests__/integration/valorant.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { client } from "@tests/__setup__/integration";

describe("Process", () => {
test("when valorant is not open, launcher is open and logged should return empty object", async () => {
const spy = jest.spyOn(client.valorant, "process");
const data = await client.valorant.process();
expect(spy).toHaveBeenCalled();
expect(data).toMatchObject({});

spy.mockRestore();
});

test("should return info about valorant process running", async () => {
const data = await client.valorant.process();

const process = Object.keys(data)[0];

expect(data[process]).toContainAllKeys([
"exitCode",
"exitReason",
"isInternal",
"launchConfiguration",
"patchlineFullName",
"patchlineId",
"phase",
"productId",
"version",
]);

expect(data[process]["launchConfiguration"]).toContainAllKeys([
"arguments",
"executable",
"locale",
"voiceLocale",
"workingDirectory",
]);
});
});

test("should return client settings", async () => {
const settings = await client.valorant.clientSettings();

expect(settings).toContainAllKeys(["data", "modified", "type"]);

expect(settings.type).toEqual("Ares.PlayerSettings");

expect(settings.data).toContainAllKeys([
"actionMappings",
"axisMappings",
"boolSettings",
"floatSettings",
"intSettings",
"roamingSetttingsVersion",
"stringSettings",
"settingsProfiles",
]);
});
226 changes: 226 additions & 0 deletions __tests__/unit/chat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
import { Chat } from "@app/chat";
import { mock } from "jest-mock-extended";

import { IHttp } from "@interfaces/http";
import { ChatInfoResponse, MessageResponse, ParticipantsResponse } from "@interfaces/chat";

const mockedHttpService = mock<IHttp>();

const chat = new Chat(mockedHttpService);

const cid = "someid@server";
const friend_pid = "friend@server";

const mockedPartyChatResponse: ChatInfoResponse = {
conversations: [
{
cid: "someid@server",
direct_messages: true,
global_readership: false,
message_history: false,
mid: "mid",
muted: false,
mutedRestriction: false,
type: "groupchat",
uiState: {
changedSinceHidden: false,
hidden: false,
},
unread_count: 0,
},
],
};

const mockedPreGameChatResponse: ChatInfoResponse = {
conversations: mockedPartyChatResponse.conversations.map((chat) => ({ ...chat, cid: "someid-1@server" })),
};

const mockedLiveGameChatResponse: ChatInfoResponse = {
conversations: [
...mockedPartyChatResponse.conversations.map((chat) => ({ ...chat, cid: "someid-blue@server" })),
{ ...mockedPartyChatResponse.conversations[0], cid: "someid-red@server" },
],
};

const mockedAllGameChatResponse: ChatInfoResponse = {
conversations: [
...mockedPreGameChatResponse.conversations,
...mockedLiveGameChatResponse.conversations,
{ ...mockedLiveGameChatResponse.conversations[0], cid: "someid-all@server" },
],
};

const mockedParticipantsResponse: ParticipantsResponse = {
participants: [
{
cid: "someid@server",
game_name: "test",
game_tag: "test",
muted: false,
name: "test",
pid: "test",
puuid: "test",
region: "test",
},
],
};

const mockedMessagesResponse: MessageResponse = {
messages: [
{
body: "eae",
cid: "someid@server",
game_name: "iws",
game_tag: "777",
id: "test",
mid: "test",
name: "test",
pid: "test",
puuid: "test",
read: true,
region: "test",
time: "test",
type: "groupchat",
},
],
};

afterEach(() => {
mockedHttpService.fetch.mockClear();
});

test("should return current info about party chat", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedPartyChatResponse);

const data = await chat.getPartyChat();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith("/chat/v6/conversations/ares-parties", "local");

expect(data).toEqual(mockedPartyChatResponse);
});

test("should return current info about pregame chat", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedPreGameChatResponse);

const data = await chat.getPreGameChat();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith("/chat/v6/conversations/ares-pregame", "local");

expect(data).toEqual(mockedPreGameChatResponse);
});

test("should return current info about livegame chat", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedLiveGameChatResponse);

const data = await chat.getLiveGameChat();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith("/chat/v6/conversations/ares-coregame", "local");

expect(data).toEqual(mockedLiveGameChatResponse);
});

test("should return current info about all chats", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedAllGameChatResponse);

const data = await chat.getAllChat();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith("/chat/v6/conversations/", "local");

expect(data).toEqual(mockedAllGameChatResponse);
});

test("should return participants in specific chat", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedParticipantsResponse);

const data = await chat.getParticipants(cid);

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith(`/chat/v5/participants/?cid=${cid}`, "local");

expect(data).toEqual(mockedParticipantsResponse);
});

test("should return all participants in all active chats", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedParticipantsResponse);

const data = await chat.getAllParticipants();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith(`/chat/v5/participants/`, "local");

expect(data).toEqual(mockedParticipantsResponse);
});

test("should return history from all active chats", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedMessagesResponse);

const data = await chat.getAllHistory();

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith("/chat/v6/messages", "local");

expect(data).toEqual(mockedMessagesResponse);
});

test("should return history from specific chat", async () => {
mockedHttpService.fetch.mockResolvedValueOnce(mockedMessagesResponse);

const data = await chat.getHistory(cid);

expect(mockedHttpService.fetch).toHaveBeenCalledTimes(1);

expect(mockedHttpService.fetch).toHaveBeenCalledWith(`/chat/v6/messages?cid=${cid}`, "local");

expect(data).toEqual(mockedMessagesResponse);
});

test("should send whisper to friend", async () => {
const mockedFriendWhisper = {
messages: [{ ...mockedMessagesResponse.messages[0], cid: friend_pid }],
};
const message = "eae";

mockedHttpService.post.mockResolvedValueOnce(mockedFriendWhisper);

const data = await chat.sendWhisper(friend_pid, message);

expect(mockedHttpService.post).toHaveBeenCalledTimes(1);

expect(mockedHttpService.post).toHaveBeenCalledWith("/chat/v6/messages/", "local", {
cid: friend_pid,
message,
type: "chat",
});

expect(data).toEqual(mockedFriendWhisper);
});

test("should send message to any chat", async () => {
mockedHttpService.post.mockClear();
mockedHttpService.post.mockResolvedValueOnce(mockedMessagesResponse);

const message = "eae";

const data = await chat.sendMessage(cid, message);

expect(mockedHttpService.post).toHaveBeenCalledTimes(1);

expect(mockedHttpService.post).toHaveBeenCalledWith("/chat/v6/messages/", "local", {
cid,
message,
type: "groupchat",
});

expect(data).toEqual(mockedMessagesResponse);
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading