"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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const os = __importStar(require("os"));
const REP_DIR = path.join(os.homedir(), '.fivo', 'cell', 'reputation');
describe('Reputation', () => {
    let module;
    beforeEach(async () => {
        module = await Promise.resolve().then(() => __importStar(require('../../walls/05-community/share/reputation')));
        if (fs.existsSync(REP_DIR)) {
            for (const f of fs.readdirSync(REP_DIR))
                fs.unlinkSync(path.join(REP_DIR, f));
        }
    });
    test('getOrCreateProfile creates new profile', () => {
        const profile = module.getOrCreateProfile('dev-123', 'Test Dev');
        expect(profile.deviceId).toBe('dev-123');
        expect(profile.displayName).toBe('Test Dev');
        expect(profile.tier).toBe('bronze');
        expect(profile.score).toBe(0);
    });
    test('getProfile returns null for unknown device', () => {
        expect(module.getProfile('unknown')).toBeNull();
    });
    test('recordContribution adds score and badges', () => {
        let profile = module.recordContribution('dev-456', { accepted: true, category: 'typescript', language: 'ts' });
        expect(profile.score).toBe(10);
        expect(profile.totalContributions).toBe(1);
        expect(profile.acceptedPatterns).toBe(1);
        expect(profile.categoryStrengths.length).toBe(1);
        expect(profile.badges.some((b) => b.id === 'first_accept')).toBe(true);
        for (let i = 0; i < 9; i++) {
            profile = module.recordContribution('dev-456', { accepted: true });
        }
        expect(profile.badges.some((b) => b.id === 'ten_accepts')).toBe(true);
    });
    test('getLeaderboard returns sorted entries', () => {
        module.recordContribution('dev-a', { accepted: true });
        module.recordContribution('dev-b', { accepted: true });
        module.recordContribution('dev-b', { accepted: true });
        const board = module.getLeaderboard(10);
        expect(board.length).toBe(2);
        expect(board[0].deviceId).toBe('dev-b');
        expect(board[0].score).toBe(20);
    });
    test('tier progression', () => {
        let profile = module.getOrCreateProfile('dev-tier', 'Tier Test');
        expect(profile.tier).toBe('bronze');
        for (let i = 0; i < 50; i++) {
            profile = module.recordContribution('dev-tier', { accepted: true });
        }
        expect(profile.score).toBe(500);
        expect(profile.tier).toBe('silver');
        for (let i = 0; i < 150; i++) {
            profile = module.recordContribution('dev-tier', { accepted: true });
        }
        expect(profile.score).toBe(2000);
        expect(profile.tier).toBe('gold');
    });
    test('getAllBadges returns all badge definitions', () => {
        const badges = module.getAllBadges();
        expect(badges.length).toBeGreaterThanOrEqual(5);
        expect(badges.some((b) => b.id === 'first_accept')).toBe(true);
    });
});
//# sourceMappingURL=reputation.test.js.map