near-protocol-rewards
Version:
A transparent, metric-based rewards system for NEAR projects
63 lines (62 loc) • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const sdk_1 = require("../../src/sdk");
const github_1 = require("../../src/collectors/github");
const logger_1 = require("../../src/utils/logger");
const rate_limiter_1 = require("../../src/utils/rate-limiter");
const github_2 = require("../../src/validators/github");
const config_validator_1 = require("../../src/utils/config-validator");
const errors_1 = require("../../src/types/errors");
jest.mock("../../src/collectors/github", () => {
return {
GitHubCollector: jest.fn().mockImplementation(() => {
return {
collectMetrics: jest.fn(),
};
}),
};
});
jest.mock("../../src/utils/logger");
jest.mock("../../src/utils/rate-limiter");
jest.mock("../../src/validators/github");
jest.mock("../../src/utils/config-validator");
describe("GitHubRewardsSDK", () => {
let config;
beforeEach(() => {
config = {
githubToken: "fake-token",
githubRepo: "fake-repo",
maxRequestsPerSecond: 5,
logger: new logger_1.ConsoleLogger(),
};
config_validator_1.validateConfig.mockReturnValue({ isValid: true, errors: [] });
});
afterEach(() => {
jest.clearAllMocks();
});
it("should throw an error if the configuration is invalid", () => {
config_validator_1.validateConfig.mockReturnValue({
isValid: false,
errors: [{ message: "Invalid configuration" }],
});
expect(() => new sdk_1.GitHubRewardsSDK(config)).toThrow(errors_1.BaseError);
expect(() => new sdk_1.GitHubRewardsSDK(config)).toThrowError("Invalid configuration");
});
it("should initialize with valid configuration", () => {
const sdk = new sdk_1.GitHubRewardsSDK(config);
expect(sdk).toBeInstanceOf(sdk_1.GitHubRewardsSDK);
expect(config_validator_1.validateConfig).toHaveBeenCalledWith(config);
expect(github_1.GitHubCollector).toHaveBeenCalledWith(expect.objectContaining({
token: config.githubToken,
repo: config.githubRepo,
}));
expect(github_2.GitHubValidator).toHaveBeenCalled();
expect(rate_limiter_1.RateLimiter).toHaveBeenCalled();
});
it("should stop tracking", async () => {
const sdk = new sdk_1.GitHubRewardsSDK(config);
sdk["isTracking"] = true;
await sdk.stopTracking();
expect(sdk["isTracking"]).toBe(false);
});
});