near-protocol-rewards
Version:
A transparent, metric-based rewards system for NEAR projects
126 lines (125 loc) • 4.54 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_validator_1 = require("../../../src/utils/config-validator");
const errors_1 = require("../../../src/types/errors");
describe('validateConfig', () => {
it('should validate a valid config', () => {
const config = {
githubToken: 'test-token',
githubRepo: 'owner/repo',
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(true);
expect(result.errors).toHaveLength(0);
expect(result.warnings).toHaveLength(0);
expect(result.metadata).toEqual({
source: 'github',
validationType: 'data',
});
expect(typeof result.timestamp).toBe('number');
});
it('should validate a valid config with postgres storage', () => {
const config = {
githubToken: 'test-token',
githubRepo: 'owner/repo',
storage: {
type: 'postgres',
config: {
host: 'localhost',
port: 5432,
database: 'test',
user: 'user',
password: 'password',
},
},
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(true);
expect(result.errors).toHaveLength(0);
});
it('should validate missing githubToken', () => {
const config = {
githubRepo: 'owner/repo',
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(false);
expect(result.errors).toHaveLength(1);
expect(result.errors[0]).toEqual({
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'githubToken is required',
});
});
it('should validate missing githubRepo', () => {
const config = {
githubToken: 'test-token',
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(false);
expect(result.errors).toHaveLength(1);
expect(result.errors[0]).toEqual({
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'githubRepo is required',
});
});
it('should validate invalid githubRepo format', () => {
const config = {
githubToken: 'test-token',
githubRepo: 'invalid-repo',
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(false);
expect(result.errors).toHaveLength(1);
expect(result.errors[0]).toEqual({
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'githubRepo must be in format "owner/repo"',
});
});
it('should validate invalid postgres config', () => {
const config = {
githubToken: 'test-token',
githubRepo: 'owner/repo',
storage: {
type: 'postgres',
config: {
host: 'localhost',
// Missing required fields
},
},
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(false);
expect(result.errors).toHaveLength(1);
expect(result.errors[0]).toEqual({
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'Invalid postgres configuration',
});
});
it('should validate multiple errors', () => {
const config = {
storage: {
type: 'postgres',
config: {
host: 'localhost',
// Missing required fields
},
},
};
const result = (0, config_validator_1.validateConfig)(config);
expect(result.isValid).toBe(false);
expect(result.errors).toHaveLength(3);
expect(result.errors).toEqual(expect.arrayContaining([
{
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'githubToken is required',
},
{
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'githubRepo is required',
},
{
code: errors_1.ErrorCode.INVALID_CONFIG,
message: 'Invalid postgres configuration',
},
]));
});
});