feat: Nambahin API untuk hapusin member dari project
This commit is contained in:
@@ -101,11 +101,83 @@ async function runTests() {
|
||||
}
|
||||
}
|
||||
|
||||
// 8. Admin accesses Project details of the mentor\'s project
|
||||
// 8. Admin accesses Project details of the mentor's project
|
||||
console.log(`8. Admin accessing details of the Mentor's project (ID: ${createdProjectId})...`);
|
||||
const adminDetailRes = await axios.get(`${BASE_URL}/project-api/get/${createdProjectId}`, getHeader(adminToken));
|
||||
console.log(` PASSED: Admin retrieved project details successfully (Name: ${adminDetailRes.data.data.project_name}).\n`);
|
||||
|
||||
// 9. Assign and Remove Member Test
|
||||
console.log('9. Testing Assign and Remove Member feature...');
|
||||
// 9.1. Get active interns
|
||||
console.log(' Fetching active interns...');
|
||||
const internsRes = await axios.get(`${BASE_URL}/project-api/interns`, getHeader(mentorToken));
|
||||
const interns = internsRes.data.data;
|
||||
if (interns.length === 0) {
|
||||
throw new Error('TEST FAILED: No interns found to test assignment!');
|
||||
}
|
||||
const testIntern = interns[0];
|
||||
console.log(` Found intern: ${testIntern.name} (ID: ${testIntern.id})`);
|
||||
|
||||
// 9.2. Assign intern to mentor's project
|
||||
console.log(` Assigning intern ID: ${testIntern.id} to project ID: ${createdProjectId}...`);
|
||||
await axios.post(`${BASE_URL}/project-api/assign-member`, {
|
||||
id_project: createdProjectId,
|
||||
id_user: testIntern.id
|
||||
}, getHeader(mentorToken));
|
||||
console.log(' PASSED: Intern assigned successfully.');
|
||||
|
||||
// 9.3. Try to remove the intern as an intern (should fail with 401/403)
|
||||
console.log(' Testing authorization: Intern trying to remove themselves or others...');
|
||||
let internToken = '';
|
||||
try {
|
||||
const internLoginRes = await axios.post(`${BASE_URL}/auth-api/login`, {
|
||||
email: 'rafi@student.com',
|
||||
password: 'password123'
|
||||
});
|
||||
internToken = internLoginRes.data.data.token;
|
||||
|
||||
await axios.post(`${BASE_URL}/project-api/remove-member`, {
|
||||
id_project: createdProjectId,
|
||||
id_user: testIntern.id
|
||||
}, getHeader(internToken));
|
||||
throw new Error('TEST FAILED: Intern successfully removed a member!');
|
||||
} catch (err) {
|
||||
if (err.response && (err.response.status === 401 || err.response.status === 403)) {
|
||||
console.log(' PASSED: Intern request denied with 401 Unauthorized / 403 Forbidden as expected.');
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// 9.4. Remove the intern as Mentor (should succeed with 200)
|
||||
console.log(` Removing intern ID: ${testIntern.id} from project ID: ${createdProjectId} as Mentor...`);
|
||||
const removeRes = await axios.post(`${BASE_URL}/project-api/remove-member`, {
|
||||
id_project: createdProjectId,
|
||||
id_user: testIntern.id
|
||||
}, getHeader(mentorToken));
|
||||
|
||||
if (removeRes.status === 200 && removeRes.data.status === true) {
|
||||
console.log(' PASSED: Intern removed successfully (200 OK).');
|
||||
} else {
|
||||
throw new Error(`TEST FAILED: Failed to remove intern. Response: ${JSON.stringify(removeRes.data)}`);
|
||||
}
|
||||
|
||||
// 9.5. Try to remove the intern again (should fail with 400 because already removed)
|
||||
console.log(' Trying to remove the already removed intern again...');
|
||||
try {
|
||||
await axios.post(`${BASE_URL}/project-api/remove-member`, {
|
||||
id_project: createdProjectId,
|
||||
id_user: testIntern.id
|
||||
}, getHeader(mentorToken));
|
||||
throw new Error('TEST FAILED: Successfully removed already removed intern!');
|
||||
} catch (err) {
|
||||
if (err.response && err.response.status === 400) {
|
||||
console.log(' PASSED: Request denied with 400 Bad Request as expected.\n');
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
console.log('=== ALL INTEGRATION TESTS PASSED SUCCESSFULLY! ===');
|
||||
} catch (err) {
|
||||
console.error('=== TEST EXECUTION ENCOUNTERED AN ERROR ===');
|
||||
|
||||
Reference in New Issue
Block a user