-
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
Showing
10 changed files
with
220 additions
and
47 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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export * from './rol.ts' | ||
export * from './rol.types.ts' | ||
export * from './zaak.mock.ts' | ||
export * from './rol.mock.ts' |
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,39 @@ | ||
import { Rol } from './rol' | ||
import { TRol } from './rol.types' | ||
|
||
export const mockRolData = (): TRol[] => [ | ||
{ | ||
uuid: '15551d6f-44e3-43f3-a9d2-59e583c91eb0', | ||
omschrijving: 'Zaak 3', | ||
omschrijvingGeneriek: 'Zaak 3', | ||
url: 'http://example.com', | ||
zaak: 'ZAAK-2024-3', | ||
betrokkene: 'string', | ||
betrokkeneType: 'string', | ||
afwijkendeNaamBetrokkene: '0a3a0ffb-dc03-4aae-b207-0ed1502e60da', | ||
roltype: 'gearchiveerd_procestermijn_onbekend', | ||
roltoelichting: '2019-08-24', | ||
registratiedatum: 'string', | ||
indicatieMachtiging: '2019-08-24', | ||
contactpersoonRol: { | ||
emailadres: '[email protected]', | ||
functie: 'something', | ||
telefoonnummer: '06 123456789', | ||
naam: 'Henry', | ||
}, | ||
statussen: ['active', 'nieuw'], | ||
_expand: { | ||
zaak: '', | ||
roltype: '', | ||
statussen: '', | ||
}, | ||
betrokkeneIdentificatie: { | ||
identificatie: '', | ||
achternaam: '', | ||
voorletters: '', | ||
voorvoegselAchternaam: '', | ||
}, | ||
}, | ||
] | ||
|
||
export const mockRol = (data: TRol[] = mockRolData()): TRol[] => data.map(item => new Rol(item)) |
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,12 @@ | ||
import { Rol } from './rol' | ||
import { mockRolData } from './rol.mock' | ||
|
||
describe('Rol Entity', () => { | ||
it('should create a Rol entity with full data', () => { | ||
const rol = new Rol(mockRolData()[0]) | ||
|
||
expect(rol).toBeInstanceOf(Rol) | ||
expect(rol).toEqual(mockRolData()[0]) | ||
expect(rol.validate().success).toBe(true) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,125 @@ | ||
/* eslint-disable no-console */ | ||
import { defineStore } from 'pinia' | ||
import { Rol } from '../../entities/index.js' | ||
|
||
const apiEndpoint = '/index.php/apps/zaakafhandelapp/api/zrc/rollen' | ||
|
||
export const useRolStore = defineStore('rollen', { | ||
state: () => ({ | ||
rolItem: false, | ||
rollenList: [], | ||
}), | ||
actions: { | ||
setRolItem(rolItem) { | ||
this.rolItem = rolItem && new Rol(rolItem) | ||
console.log('Active rol item set to ' + rolItem) | ||
}, | ||
setRollenList(rollenList) { | ||
this.rollenList = rollenList.map( | ||
(rolItem) => new Rol(rolItem), | ||
) | ||
console.log('Rollen list set to ' + rollenList.length + ' items') | ||
}, | ||
/* istanbul ignore next */ // ignore this for Jest until moved into a service | ||
async refreshRollenList(search = null) { | ||
let endpoint = apiEndpoint | ||
|
||
if (search !== null && search !== '') { | ||
endpoint = endpoint + '?_search=' + search | ||
} | ||
|
||
const response = await fetch(endpoint, { | ||
method: 'GET', | ||
}) | ||
|
||
if (!response.ok) { | ||
console.log(response) | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data = (await response.json()).results | ||
const entities = data.map((rolItem) => new Rol(rolItem)) | ||
|
||
this.setRollenList(data) | ||
|
||
return { response, data, entities } | ||
}, | ||
// New function to get a single rol | ||
async getRol(id) { | ||
const endpoint = `${apiEndpoint}/${id}` | ||
|
||
const response = await fetch(endpoint, { | ||
method: 'GET', | ||
}) | ||
|
||
if (!response.ok) { | ||
console.log(response) | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data = await response.json() | ||
const entity = new Rol(data) | ||
|
||
this.setRolItem(data) | ||
|
||
return { response, data, entity } | ||
}, | ||
// Delete a rol | ||
async deleteRol(rolItem) { | ||
if (!rolItem.id) { | ||
throw new Error('No rol item to delete') | ||
} | ||
|
||
const endpoint = `${apiEndpoint}/${rolItem.id}` | ||
|
||
const response = await fetch(endpoint, { | ||
method: 'DELETE', | ||
}) | ||
|
||
if (!response.ok) { | ||
console.log(response) | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
this.refreshRollenList() | ||
|
||
return { response } | ||
}, | ||
// Create or save a rol from store | ||
async saveRol(rolItem) { | ||
if (!rolItem) { | ||
throw new Error('No rol item to save') | ||
} | ||
|
||
const isNewRol = !rolItem.id | ||
const endpoint = isNewRol | ||
? `${apiEndpoint}` | ||
: `${apiEndpoint}/${rolItem.id}` | ||
const method = isNewRol ? 'POST' : 'PUT' | ||
|
||
const response = await fetch( | ||
endpoint, | ||
{ | ||
method, | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify(rolItem), | ||
}, | ||
) | ||
|
||
if (!response.ok) { | ||
console.log(response) | ||
throw new Error(`HTTP error! status: ${response.status}`) | ||
} | ||
|
||
const data = await response.json() | ||
const entity = new Rol(data) | ||
|
||
this.setRolItem(data) | ||
this.refreshRollenList() | ||
|
||
return { response, data, entity } | ||
}, | ||
}, | ||
}) |
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,36 @@ | ||
/* eslint-disable no-console */ | ||
import { setActivePinia, createPinia } from 'pinia' | ||
|
||
import { useZaakStore } from './zaken.js' | ||
import { Zaak, mockZaak } from '../../entities/index.js' | ||
|
||
describe('Zaak Store', () => { | ||
beforeEach(() => { | ||
setActivePinia(createPinia()) | ||
}) | ||
|
||
it('sets zaak item correctly', () => { | ||
const store = useZaakStore() | ||
|
||
store.setZaakItem(mockZaak()[0]) | ||
|
||
expect(store.zaakItem).toBeInstanceOf(Zaak) | ||
expect(store.zaakItem).toEqual(mockZaak()[0]) | ||
|
||
expect(store.zaakItem.validate().success).toBe(true) | ||
}) | ||
|
||
it('sets zaken list correctly', () => { | ||
const store = useZaakStore() | ||
|
||
store.setZakenList(mockZaak()) | ||
|
||
expect(store.zakenList).toHaveLength(mockZaak().length) | ||
|
||
store.zakenList.forEach((item, index) => { | ||
expect(item).toBeInstanceOf(Zaak) | ||
expect(item).toEqual(mockZaak()[index]) | ||
expect(item.validate().success).toBe(true) | ||
}) | ||
}) | ||
}) |
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