-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7adccb9
commit 5125954
Showing
25 changed files
with
1,387 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
describe('Administration logs', () => { | ||
let logCount | ||
let logs | ||
|
||
beforeEach(() => { | ||
cy.intercept('GET', 'api/v1/admin/logs/count').as('countLogs') | ||
cy.intercept('GET', 'api/v1/admin/logs/0/5').as('getAllLogs') | ||
|
||
cy.kcLogin('tcolin') | ||
cy.visit('/admin/logs') | ||
cy.url().should('contain', '/admin/logs') | ||
cy.wait('@countLogs', { timeout: 10000 }).its('response').then(response => { | ||
logCount = response?.body | ||
}) | ||
cy.wait('@getAllLogs', { timeout: 10000 }).its('response').then(response => { | ||
logs = response?.body | ||
}) | ||
}) | ||
|
||
it('Should display logs list, loggedIn as admin', () => { | ||
cy.getByDataTestid('logCountInfo').should('contain', `Total : ${logCount} logs`) | ||
logs.forEach(log => { | ||
cy.getByDataTestid(`${log.id}-json`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { defineStore } from 'pinia' | ||
import api from '@/api/index.js' | ||
|
||
export const useAdminLogStore = defineStore('admin-log', () => { | ||
const getAllLogs = async ({ offset, limit } = { offset: 0, limit: 100 }) => { | ||
return api.getAllLogs({ offset, limit }) | ||
} | ||
|
||
const countAllLogs = async () => { | ||
return api.countAllLogs() | ||
} | ||
|
||
return { | ||
getAllLogs, | ||
countAllLogs, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { vi, describe, it, expect, beforeEach } from 'vitest' | ||
import { setActivePinia, createPinia } from 'pinia' | ||
import { apiClient } from '../../api/xhr-client.js' | ||
import { useAdminLogStore } from './log.js' | ||
|
||
vi.spyOn(apiClient, 'get') | ||
vi.spyOn(apiClient, 'post') | ||
vi.spyOn(apiClient, 'put') | ||
vi.spyOn(apiClient, 'patch') | ||
vi.spyOn(apiClient, 'delete') | ||
|
||
describe('Counter Store', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks() | ||
// creates a fresh pinia and make it active so it's automatically picked | ||
// up by any useStore() call without having to pass it to it: `useStore(pinia)` | ||
setActivePinia(createPinia()) | ||
}) | ||
|
||
it('Should get organization list by api call', async () => { | ||
const data = [ | ||
{ id: 'thisIsAnId', data: {}, action: 'Create Project', userId: 'cb8e5b4b-7b7b-40f5-935f-594f48ae6565' }, | ||
] | ||
apiClient.get.mockReturnValueOnce(Promise.resolve({ data })) | ||
const adminLogStore = useAdminLogStore() | ||
|
||
const res = await adminLogStore.getAllLogs({ offset: 5, limit: 10 }) | ||
|
||
expect(res).toBe(data) | ||
expect(apiClient.get).toHaveBeenCalledTimes(1) | ||
expect(apiClient.get.mock.calls[0][0]).toBe('/admin/logs/5/10') | ||
}) | ||
|
||
it('Should count logs by api call', async () => { | ||
const data = 12 | ||
apiClient.get.mockReturnValueOnce(Promise.resolve({ data })) | ||
const adminLogStore = useAdminLogStore() | ||
|
||
const res = await adminLogStore.countAllLogs() | ||
|
||
expect(res).toBe(data) | ||
expect(apiClient.get).toHaveBeenCalledTimes(1) | ||
expect(apiClient.get.mock.calls[0][0]).toBe('/admin/logs/count') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<script setup> | ||
import { ref, onMounted } from 'vue' | ||
import { useAdminLogStore } from '@/stores/admin/log.js' | ||
import { useSnackbarStore } from '@/stores/snackbar.js' | ||
import { JsonViewer } from 'vue3-json-viewer' | ||
const adminLogStore = useAdminLogStore() | ||
const snackbarStore = useSnackbarStore() | ||
const step = 5 | ||
const isUpdating = ref(true) | ||
const logs = ref(undefined) | ||
const logsLength = ref(0) | ||
const logsPagination = ref({ | ||
offset: 0, | ||
limit: step, | ||
}) | ||
const showLogs = async (key) => { | ||
if (key === 'first' || | ||
(key === 'previous' && | ||
(logsPagination.value.offset < 0 || | ||
logsPagination.value.limit < step)) | ||
) { | ||
logsPagination.value.offset = 0 | ||
logsPagination.value.limit = step | ||
} else if (key === 'previous') { | ||
logsPagination.value.offset -= step | ||
logsPagination.value.limit -= step | ||
} else if (key === 'last' || | ||
(key === 'next' && | ||
logsPagination.value.offset >= logsLength.value - step)) { | ||
logsPagination.value.offset = logsLength.value - step | ||
logsPagination.value.limit = logsLength.value | ||
} else { | ||
logsPagination.value.offset += step | ||
logsPagination.value.limit += step | ||
} | ||
await getAllLogs({ offset: logsPagination.value.offset, limit: logsPagination.value.limit }) | ||
} | ||
const getAllLogs = async ({ offset, limit }, isDisplayingSuccess = true) => { | ||
isUpdating.value = true | ||
try { | ||
logs.value = await adminLogStore.getAllLogs({ offset, limit }) | ||
if (isDisplayingSuccess) { | ||
snackbarStore.setMessage('Logs récupérés avec succès', 'success') | ||
} | ||
} catch (error) { | ||
snackbarStore.setMessage(error?.message, 'error') | ||
} | ||
isUpdating.value = false | ||
} | ||
const refreshLogs = async ({ offset, limit }) => { | ||
logsLength.value = await adminLogStore.countAllLogs() | ||
await getAllLogs({ offset, limit }) | ||
} | ||
onMounted(async () => { | ||
await getAllLogs({ offset: logsPagination.value.offset, limit: logsPagination.value.limit }, false) | ||
logsLength.value = await adminLogStore.countAllLogs() | ||
}) | ||
</script> | ||
<template> | ||
<h1 | ||
class="fr-h3" | ||
> | ||
Logs des services associés à la chaîne DSO | ||
</h1> | ||
<div | ||
class="flex justify-between" | ||
> | ||
<DsfrAlert | ||
v-if="!isUpdating" | ||
:description="!logsLength ? 'Aucun logs en base de donnée.' : `Total : ${logsLength} logs`" | ||
data-testid="logCountInfo" | ||
type="info" | ||
small | ||
/> | ||
<DsfrButton | ||
data-testid="refresh-btn" | ||
title="Renouveler l'appel" | ||
secondary | ||
icon-only | ||
icon="ri-refresh-fill" | ||
:disabled="isUpdating === true" | ||
@click="refreshLogs({ offset: logsPagination.offset, limit: logsPagination.limit })" | ||
/> | ||
</div> | ||
<JsonViewer | ||
v-for="log in logs" | ||
:key="log.id" | ||
:data-testid="`${log.id}-json`" | ||
:value="log" | ||
class="log-box" | ||
copyable | ||
boxed | ||
/> | ||
<div | ||
class="flex justify-between" | ||
> | ||
<div | ||
class="flex gap-2" | ||
> | ||
<DsfrButton | ||
title="voir les premiers logs" | ||
secondary | ||
icon-only | ||
:disabled="isUpdating === true || logsPagination.offset <= 0" | ||
icon="ri-arrow-drop-left-fill" | ||
@click="showLogs('first')" | ||
/> | ||
<DsfrButton | ||
title="voir les logs précédents" | ||
secondary | ||
icon-only | ||
:disabled="isUpdating === true || logsPagination.offset <= 0" | ||
icon="ri-arrow-drop-left-line" | ||
@click="showLogs('previous')" | ||
/> | ||
</div> | ||
<div | ||
class="flex gap-2" | ||
> | ||
<DsfrButton | ||
title="voir les logs suivants" | ||
secondary | ||
icon-only | ||
:disabled="isUpdating === true || logsPagination.offset >= logsLength - step" | ||
icon="ri-arrow-drop-right-line" | ||
@click="showLogs('next')" | ||
/> | ||
<DsfrButton | ||
title="voir les derniers logs" | ||
secondary | ||
icon-only | ||
:disabled="isUpdating === true || logsPagination.offset >= logsLength - step" | ||
icon="ri-arrow-drop-right-fill" | ||
@click="showLogs('last')" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
<style> | ||
.log-box.jv-container span.jv-item.jv-object, | ||
.log-box.jv-container span.jv-key { | ||
color: var(--text-default-grey); | ||
} | ||
.log-box.jv-container { | ||
@apply my-6; | ||
background-color: var(--background-default-grey); | ||
} | ||
</style> |
Oops, something went wrong.