Skip to content

Commit

Permalink
Merge pull request #34 from Ximaz/unit-tests
Browse files Browse the repository at this point in the history
Adding unit tests, adding the pinned server feature.
  • Loading branch information
Ximaz authored Oct 17, 2023
2 parents 9565a08 + 93c214d commit bd0e940
Show file tree
Hide file tree
Showing 68 changed files with 4,873 additions and 2,416 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
dist
tests
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"plugin:@typescript-eslint/recommended"
],
"rules": {
"no-console": 2
"no-console": 2,
"@typescript-eslint/no-explicit-any": ["off"]
}
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: PABLO-1610
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2

updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
23 changes: 23 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: ESLint

on: [push, pull_request]

jobs:
lint:
name: ESLint
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Node
uses: actions/setup-node@v2
with:
node-version: 16
cache: npm

- name: Install ESLint
run: npm install

- name: Run ESLint
run: npm run lint
44 changes: 44 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Node.js Package

on:
release:
types: [ created ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
- run: npm ci
- run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-gpr:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GIT_TOKEN}}
35 changes: 35 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: unit-tests

on:
workflow_dispatch:
push:
pull_request:

jobs:
check_lib_compilation:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Install Dependencies
run: npm i --save

- name: Compile Library
run: npm run compile

run_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
with:
fetch-depth: 0

- name: Install Dependencies
run: npm i -D

- name: Execute Unit Tests
run: npm run test
9 changes: 5 additions & 4 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./types";
export declare function fetchServer(id: string): Promise<import("./models/CfxCitizenServer").default | undefined>;
export declare function fetchStatus(): Promise<import("./models/CfxStatus").default | undefined>;
export declare function fetchUnresolvedIncidents(): Promise<import("./types").CfxUnresolvedIncidents | undefined>;
export * from "./types";
export declare function fetchServer(id: string): Promise<import("./models/CfxCitizenServer").default | undefined>;
export declare function fetchStatus(): Promise<import("./models/CfxStatus").default | undefined>;
export declare function fetchUnresolvedIncidents(): Promise<import("./models/CfxUnresolvedIncidents").default | undefined>;
export declare function fetchPinnedServers(): Promise<import("./models/CfxPinnedServers").default | undefined>;
77 changes: 41 additions & 36 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchUnresolvedIncidents = exports.fetchStatus = exports.fetchServer = void 0;
const CfxStatus_module_1 = __importDefault(require("./modules/CfxStatus.module"));
const CfxCitizenServer_module_1 = __importDefault(require("./modules/CfxCitizenServer.module"));
const CfxUnresolvedIncidents_module_1 = __importDefault(require("./modules/CfxUnresolvedIncidents.module"));
__exportStar(require("./types"), exports);
async function fetchServer(id) {
return await CfxCitizenServer_module_1.default.get().retrieve(id);
}
exports.fetchServer = fetchServer;
async function fetchStatus() {
return await CfxStatus_module_1.default.get().retrieve();
}
exports.fetchStatus = fetchStatus;
async function fetchUnresolvedIncidents() {
return await CfxUnresolvedIncidents_module_1.default.get().retrieve();
}
exports.fetchUnresolvedIncidents = fetchUnresolvedIncidents;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchPinnedServers = exports.fetchUnresolvedIncidents = exports.fetchStatus = exports.fetchServer = void 0;
const CfxStatus_module_1 = __importDefault(require("./modules/CfxStatus.module"));
const CfxCitizenServer_module_1 = __importDefault(require("./modules/CfxCitizenServer.module"));
const CfxUnresolvedIncidents_module_1 = __importDefault(require("./modules/CfxUnresolvedIncidents.module"));
const CfxPinnedServers_module_1 = __importDefault(require("./modules/CfxPinnedServers.module"));
__exportStar(require("./types"), exports);
async function fetchServer(id) {
return await CfxCitizenServer_module_1.default.get().retrieve(id);
}
exports.fetchServer = fetchServer;
async function fetchStatus() {
return await CfxStatus_module_1.default.get().retrieve();
}
exports.fetchStatus = fetchStatus;
async function fetchUnresolvedIncidents() {
return await CfxUnresolvedIncidents_module_1.default.get().retrieve();
}
exports.fetchUnresolvedIncidents = fetchUnresolvedIncidents;
async function fetchPinnedServers() {
return await CfxPinnedServers_module_1.default.get().retrieve();
}
exports.fetchPinnedServers = fetchPinnedServers;
18 changes: 9 additions & 9 deletions dist/models/CfxCitizenPlayer.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CfxCitizenPlayerPayload } from "../types";
export default class CfxCitizenPlayer {
endpoint: string;
id: number;
identifiers: string[];
name: string;
ping: number;
constructor(payload: CfxCitizenPlayerPayload);
}
import { CfxCitizenPlayerPayload } from "../types";
export default class CfxCitizenPlayer {
endpoint: string;
id: number;
identifiers: string[];
name: string;
ping: number;
constructor(payload: CfxCitizenPlayerPayload);
}
34 changes: 17 additions & 17 deletions dist/models/CfxCitizenPlayer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class CfxCitizenPlayer {
endpoint;
id;
identifiers;
name;
ping;
constructor(payload) {
this.endpoint = payload.endpoint;
this.id = payload.id;
this.identifiers = payload.identifiers;
this.name = payload.name;
this.ping = payload.ping;
}
}
exports.default = CfxCitizenPlayer;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class CfxCitizenPlayer {
endpoint;
id;
identifiers;
name;
ping;
constructor(payload) {
this.endpoint = payload.endpoint;
this.id = payload.id;
this.identifiers = payload.identifiers;
this.name = payload.name;
this.ping = payload.ping;
}
}
exports.default = CfxCitizenPlayer;
78 changes: 39 additions & 39 deletions dist/models/CfxCitizenServer.d.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { CfxCitizenServerData, CfxCitizenServerDataData } from "../types";
export default class CitizenServer {
id: string;
data: CfxCitizenServerDataData;
constructor(data: CfxCitizenServerData);
get playersCount(): number;
get players(): import("../types").CfxCitizenPlayerPayload[];
get gameType(): string;
get hostname(): string;
get mapName(): string;
get maxPlayers(): number;
get enhancedHostSupport(): boolean;
get resources(): string[];
get serverVersion(): string;
get publicVariables(): import("../types").CfxCitizenServerDataPublicVariables;
get playersCountFromServerReport(): number;
get ownerId(): number;
get private(): boolean;
get fallback(): boolean;
get connectedEndpoints(): string[];
get upvotePower(): number;
get burstPower(): number;
get supported(): string;
get ownerName(): string;
get ownerProfileUrl(): string;
get ownerAvatarUrl(): string;
get lastSeenDate(): string;
get iconVersion(): number;
get isOneSyncEnabled(): boolean;
get elementClub(): string;
get tags(): string[];
get projectName(): string;
get projectDesc(): string;
get isFull(): boolean;
hasResource(resource: string): boolean;
hasAnyResourceStartingWith(resource: string): boolean;
hasTag(tag: string): boolean;
isPlayerOnline(name: string): boolean;
}
import { CfxCitizenServerData, CfxCitizenServerDataData } from "../types";
export default class CitizenServer {
id: string;
data: CfxCitizenServerDataData;
constructor(data: CfxCitizenServerData);
get playersCount(): number;
get players(): import("../types").CfxCitizenPlayerPayload[];
get gameType(): string;
get hostname(): string;
get mapName(): string;
get maxPlayers(): number;
get enhancedHostSupport(): boolean;
get resources(): string[];
get serverVersion(): string;
get publicVariables(): import("../types").CfxCitizenServerDataPublicVariables;
get playersCountFromServerReport(): number;
get ownerId(): number;
get private(): boolean;
get fallback(): boolean;
get connectedEndpoints(): string[];
get upvotePower(): number;
get burstPower(): number;
get supported(): string;
get ownerName(): string;
get ownerProfileUrl(): string;
get ownerAvatarUrl(): string;
get lastSeenDate(): string;
get iconVersion(): number;
get isOneSyncEnabled(): boolean;
get elementClub(): string;
get tags(): string[];
get projectName(): string;
get projectDesc(): string;
get isFull(): boolean;
hasResource(resource: string): boolean;
hasAnyResourceStartingWith(resource: string): boolean;
hasTag(tag: string): boolean;
isPlayerOnline(name: string): boolean;
}
Loading

0 comments on commit bd0e940

Please sign in to comment.