1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-24 15:49:46 +02:00

add test for dashboard

Signed-off-by: nabim777 <nabinalemagar019@gmail.com>
This commit is contained in:
nabim777 2024-10-07 09:58:56 +05:45
parent 95c8175e8c
commit db81ebcc7f
No known key found for this signature in database
GPG key ID: 6EBA146273BEC371
6 changed files with 114 additions and 1 deletions

View file

@ -0,0 +1,56 @@
const axios = require('axios');
async function getXauthToken() {
try {
const res = await axios.post(
'http://localhost:1337/api/access-tokens',
{
emailOrUsername: 'demo',
password: 'demo',
},
{
headers: {
'Content-Type': 'application/json',
},
},
);
return res.data.item;
} catch (error) {
return `Error requesting access token: ${error.message}`;
}
}
async function getProjectIDs() {
try {
const res = await axios.get('http://localhost:1337/api/projects', {
headers: {
Authorization: `Bearer ${await getXauthToken()}`,
},
});
return res.data.items.map((project) => project.id);
} catch (error) {
return `Error requesting projectIDs: ${error.message}`;
}
}
async function deleteProject() {
try {
const projectIDs = await getProjectIDs();
await Promise.all(
projectIDs.map(async (project) => {
await axios.delete(`http://localhost:1337/api/projects/${project}`, {
headers: {
Authorization: `Bearer ${await getXauthToken()}`,
},
});
}),
);
return true;
} catch (error) {
return `Error deleting project: ${error.message}`;
}
}
module.exports = {
deleteProject,
};