| "use strict"; |
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
| function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
| return new (P || (P = Promise))(function (resolve, reject) { |
| function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
| function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
| function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
| step((generator = generator.apply(thisArg, _arguments || [])).next()); |
| }); |
| }; |
| var __importDefault = (this && this.__importDefault) || function (mod) { |
| return (mod && mod.__esModule) ? mod : { "default": mod }; |
| }; |
| Object.defineProperty(exports, "__esModule", { value: true }); |
| const axios_1 = __importDefault(require("axios")); |
| const API_URL = 'http://localhost:8000/api'; |
| |
| const ADMIN_TOKEN = 'YOUR_ADMIN_TOKEN'; |
| const TRAINER_TOKEN = 'YOUR_TRAINER_TOKEN'; |
| function testLogging() { |
| return __awaiter(this, void 0, void 0, function* () { |
| var _a, _b, _c, _d; |
| try { |
| console.log('--- Testing Admin Access ---'); |
| |
| console.log('1. Fetching all logs (Admin)...'); |
| try { |
| const allLogs = yield axios_1.default.get(`${API_URL}/activity/timeline`, { |
| headers: { Authorization: `Bearer ${ADMIN_TOKEN}` } |
| }); |
| console.log(`Success: Fetched ${allLogs.data.data.activities.length} logs.`); |
| } |
| catch (e) { |
| console.error('Failed to fetch all logs:', ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data) || e.message); |
| } |
| |
| console.log('\n2. Filtering by role "trainer" (Admin)...'); |
| try { |
| const trainerLogs = yield axios_1.default.get(`${API_URL}/activity/timeline?role=trainer`, { |
| headers: { Authorization: `Bearer ${ADMIN_TOKEN}` } |
| }); |
| console.log(`Success: Fetched ${trainerLogs.data.data.activities.length} trainer logs.`); |
| } |
| catch (e) { |
| console.error('Failed to fetch trainer logs:', ((_b = e.response) === null || _b === void 0 ? void 0 : _b.data) || e.message); |
| } |
| console.log('\n--- Testing User Access ---'); |
| |
| console.log('3. Fetching own logs (Trainer)...'); |
| try { |
| const ownLogs = yield axios_1.default.get(`${API_URL}/activity/timeline`, { |
| headers: { Authorization: `Bearer ${TRAINER_TOKEN}` } |
| }); |
| console.log(`Success: Fetched ${ownLogs.data.data.activities.length} own logs.`); |
| } |
| catch (e) { |
| console.error('Failed to fetch own logs:', ((_c = e.response) === null || _c === void 0 ? void 0 : _c.data) || e.message); |
| } |
| |
| console.log('4. Attempting to fetch other user logs (Trainer)...'); |
| try { |
| const otherLogs = yield axios_1.default.get(`${API_URL}/activity/timeline?userId=SOME_OTHER_ID`, { |
| headers: { Authorization: `Bearer ${TRAINER_TOKEN}` } |
| }); |
| |
| console.log(`Success (Expected): Fetched ${otherLogs.data.data.activities.length} logs (should be own logs).`); |
| } |
| catch (e) { |
| console.error('Failed (Unexpected):', ((_d = e.response) === null || _d === void 0 ? void 0 : _d.data) || e.message); |
| } |
| } |
| catch (error) { |
| console.error('Test failed:', error); |
| } |
| }); |
| } |
| testLogging(); |
|
|