feat/49-provenance #54
@@ -15,6 +15,90 @@ class Api {
|
||||
return this.apiImplementation.updateProduct(productId, data);
|
||||
}
|
||||
|
||||
getProduct(productId) {
|
||||
return this.apiImplementation.getProduct(productId);
|
||||
}
|
||||
|
||||
getOrganizations() {
|
||||
return this.apiImplementation.getOrganizations();
|
||||
}
|
||||
|
||||
createOrganization(data) {
|
||||
return this.apiImplementation.createOrganization(data);
|
||||
}
|
||||
|
||||
updateOrganization(id, data) {
|
||||
return this.apiImplementation.updateOrganization(id, data);
|
||||
}
|
||||
|
||||
deleteOrganization(id) {
|
||||
return this.apiImplementation.deleteOrganization(id);
|
||||
}
|
||||
|
||||
getSuppliers() {
|
||||
return this.apiImplementation.getSuppliers();
|
||||
}
|
||||
|
||||
createSupplier(data) {
|
||||
return this.apiImplementation.createSupplier(data);
|
||||
}
|
||||
|
||||
updateSupplier(id, data) {
|
||||
return this.apiImplementation.updateSupplier(id, data);
|
||||
}
|
||||
|
||||
deleteSupplier(id) {
|
||||
return this.apiImplementation.deleteSupplier(id);
|
||||
}
|
||||
|
||||
getCountries() {
|
||||
return this.apiImplementation.getCountries();
|
||||
}
|
||||
|
||||
createCountry(data) {
|
||||
return this.apiImplementation.createCountry(data);
|
||||
}
|
||||
|
||||
updateCountry(id, data) {
|
||||
return this.apiImplementation.updateCountry(id, data);
|
||||
}
|
||||
|
||||
deleteCountry(id) {
|
||||
return this.apiImplementation.deleteCountry(id);
|
||||
}
|
||||
|
||||
getDepartments() {
|
||||
return this.apiImplementation.getDepartments();
|
||||
}
|
||||
|
||||
createDepartment(data) {
|
||||
return this.apiImplementation.createDepartment(data);
|
||||
}
|
||||
|
||||
updateDepartment(id, data) {
|
||||
return this.apiImplementation.updateDepartment(id, data);
|
||||
}
|
||||
|
||||
deleteDepartment(id) {
|
||||
return this.apiImplementation.deleteDepartment(id);
|
||||
}
|
||||
|
||||
getMunicipalities() {
|
||||
return this.apiImplementation.getMunicipalities();
|
||||
}
|
||||
|
||||
createMunicipality(data) {
|
||||
return this.apiImplementation.createMunicipality(data);
|
||||
}
|
||||
|
||||
updateMunicipality(id, data) {
|
||||
return this.apiImplementation.updateMunicipality(id, data);
|
||||
}
|
||||
|
||||
deleteMunicipality(id) {
|
||||
return this.apiImplementation.deleteMunicipality(id);
|
||||
}
|
||||
|
||||
getPaymentMethods() {
|
||||
return this.apiImplementation.getPaymentMethods();
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ class DjangoApi {
|
||||
return http.patch(url, payload).then((r) => r.data);
|
||||
}
|
||||
|
||||
deleteRequest(url) {
|
||||
return http.delete(url).then((r) => r.data);
|
||||
}
|
||||
|
||||
getCustomers() {
|
||||
const url = this.base + "/don_confiao/api/customers/";
|
||||
return this.getRequest(url);
|
||||
@@ -39,6 +43,111 @@ class DjangoApi {
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
getProduct(productId) {
|
||||
const url = this.base + `/don_confiao/api/products/${productId}/`;
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
getOrganizations() {
|
||||
const url = this.base + "/don_confiao/api/organizations/";
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
createOrganization(data) {
|
||||
const url = this.base + "/don_confiao/api/organizations/";
|
||||
return this.postRequest(url, data);
|
||||
}
|
||||
|
||||
updateOrganization(id, data) {
|
||||
const url = this.base + `/don_confiao/api/organizations/${id}/`;
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
deleteOrganization(id) {
|
||||
const url = this.base + `/don_confiao/api/organizations/${id}/`;
|
||||
return this.deleteRequest(url);
|
||||
}
|
||||
|
||||
getSuppliers() {
|
||||
const url = this.base + "/don_confiao/api/suppliers/";
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
createSupplier(data) {
|
||||
const url = this.base + "/don_confiao/api/suppliers/";
|
||||
return this.postRequest(url, data);
|
||||
}
|
||||
|
||||
updateSupplier(id, data) {
|
||||
const url = this.base + `/don_confiao/api/suppliers/${id}/`;
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
deleteSupplier(id) {
|
||||
const url = this.base + `/don_confiao/api/suppliers/${id}/`;
|
||||
return this.deleteRequest(url);
|
||||
}
|
||||
|
||||
getCountries() {
|
||||
const url = this.base + "/don_confiao/api/countries/";
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
createCountry(data) {
|
||||
const url = this.base + "/don_confiao/api/countries/";
|
||||
return this.postRequest(url, data);
|
||||
}
|
||||
|
||||
updateCountry(id, data) {
|
||||
const url = this.base + `/don_confiao/api/countries/${id}/`;
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
deleteCountry(id) {
|
||||
const url = this.base + `/don_confiao/api/countries/${id}/`;
|
||||
return this.deleteRequest(url);
|
||||
}
|
||||
|
||||
getDepartments() {
|
||||
const url = this.base + "/don_confiao/api/departments/";
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
createDepartment(data) {
|
||||
const url = this.base + "/don_confiao/api/departments/";
|
||||
return this.postRequest(url, data);
|
||||
}
|
||||
|
||||
updateDepartment(id, data) {
|
||||
const url = this.base + `/don_confiao/api/departments/${id}/`;
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
deleteDepartment(id) {
|
||||
const url = this.base + `/don_confiao/api/departments/${id}/`;
|
||||
return this.deleteRequest(url);
|
||||
}
|
||||
|
||||
getMunicipalities() {
|
||||
const url = this.base + "/don_confiao/api/municipalities/";
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
createMunicipality(data) {
|
||||
const url = this.base + "/don_confiao/api/municipalities/";
|
||||
return this.postRequest(url, data);
|
||||
}
|
||||
|
||||
updateMunicipality(id, data) {
|
||||
const url = this.base + `/don_confiao/api/municipalities/${id}/`;
|
||||
return this.patchRequest(url, data);
|
||||
}
|
||||
|
||||
deleteMunicipality(id) {
|
||||
const url = this.base + `/don_confiao/api/municipalities/${id}/`;
|
||||
return this.deleteRequest(url);
|
||||
}
|
||||
|
||||
getPaymentMethods() {
|
||||
const url =
|
||||
this.base + "/don_confiao/payment_methods/all/select_format";
|
||||
|
||||
@@ -32,3 +32,186 @@ describe('DjangoApi.getPublicOrderSummary', () => {
|
||||
expect(result).toEqual({ code: 'abc123', type: 'sale' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('DjangoApi provenance CRUD', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubEnv('VITE_DJANGO_BASE_URL', 'http://backend.test')
|
||||
http.get.mockReset()
|
||||
http.post.mockReset()
|
||||
http.patch.mockReset()
|
||||
http.delete.mockReset()
|
||||
http.get.mockResolvedValue({ data: [] })
|
||||
http.post.mockResolvedValue({ data: { id: 1 } })
|
||||
http.patch.mockResolvedValue({ data: { id: 1 } })
|
||||
http.delete.mockResolvedValue({ data: {} })
|
||||
})
|
||||
|
||||
it('getProduct consulta el detalle autenticado del producto', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getProduct(3)
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/products/3/'
|
||||
)
|
||||
})
|
||||
|
||||
it('getOrganizations consulta la lista de organizaciones', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getOrganizations()
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/organizations/'
|
||||
)
|
||||
})
|
||||
|
||||
it('createOrganization hace POST con los datos', async () => {
|
||||
const api = new DjangoApi()
|
||||
const payload = { name: 'Red de Economía Solidaria' }
|
||||
|
||||
await api.createOrganization(payload)
|
||||
|
||||
expect(http.post).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/organizations/',
|
||||
payload
|
||||
)
|
||||
})
|
||||
|
||||
it('updateOrganization hace PATCH con los datos', async () => {
|
||||
const api = new DjangoApi()
|
||||
const payload = { description: 'Nueva descripción' }
|
||||
|
||||
await api.updateOrganization(3, payload)
|
||||
|
||||
expect(http.patch).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/organizations/3/',
|
||||
payload
|
||||
)
|
||||
})
|
||||
|
||||
it('deleteOrganization hace DELETE', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.deleteOrganization(3)
|
||||
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/organizations/3/'
|
||||
)
|
||||
})
|
||||
|
||||
it('getSuppliers consulta la lista de proveedores', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getSuppliers()
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/suppliers/'
|
||||
)
|
||||
})
|
||||
|
||||
it('createSupplier hace POST con datos de proveedor', async () => {
|
||||
const api = new DjangoApi()
|
||||
const payload = { name: 'Asociación La Mesa', organization: 3, municipality: 7 }
|
||||
|
||||
await api.createSupplier(payload)
|
||||
|
||||
expect(http.post).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/suppliers/',
|
||||
payload
|
||||
)
|
||||
})
|
||||
|
||||
it('updateSupplier hace PATCH para desvincular organización con null', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.updateSupplier(5, { organization: null })
|
||||
|
||||
expect(http.patch).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/suppliers/5/',
|
||||
{ organization: null }
|
||||
)
|
||||
})
|
||||
|
||||
it('deleteSupplier hace DELETE', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.deleteSupplier(5)
|
||||
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/suppliers/5/'
|
||||
)
|
||||
})
|
||||
|
||||
it('CRUD de países usa el endpoint countries', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getCountries()
|
||||
await api.createCountry({ name: 'Colombia', code: 'CO' })
|
||||
await api.updateCountry(1, { code: 'CO' })
|
||||
await api.deleteCountry(1)
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/countries/'
|
||||
)
|
||||
expect(http.post).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/countries/',
|
||||
{ name: 'Colombia', code: 'CO' }
|
||||
)
|
||||
expect(http.patch).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/countries/1/',
|
||||
{ code: 'CO' }
|
||||
)
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/countries/1/'
|
||||
)
|
||||
})
|
||||
|
||||
it('CRUD de departamentos usa el endpoint departments', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getDepartments()
|
||||
await api.createDepartment({ name: 'Cundinamarca', country: 1 })
|
||||
await api.updateDepartment(2, { name: 'Antioquia' })
|
||||
await api.deleteDepartment(2)
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/departments/'
|
||||
)
|
||||
expect(http.post).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/departments/',
|
||||
{ name: 'Cundinamarca', country: 1 }
|
||||
)
|
||||
expect(http.patch).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/departments/2/',
|
||||
{ name: 'Antioquia' }
|
||||
)
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/departments/2/'
|
||||
)
|
||||
})
|
||||
|
||||
it('CRUD de municipios usa el endpoint municipalities', async () => {
|
||||
const api = new DjangoApi()
|
||||
|
||||
await api.getMunicipalities()
|
||||
await api.createMunicipality({ name: 'La Mesa', department: 2, country: 1 })
|
||||
await api.updateMunicipality(7, { name: 'LA MESA' })
|
||||
await api.deleteMunicipality(7)
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/municipalities/'
|
||||
)
|
||||
expect(http.post).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/municipalities/',
|
||||
{ name: 'La Mesa', department: 2, country: 1 }
|
||||
)
|
||||
expect(http.patch).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/municipalities/7/',
|
||||
{ name: 'LA MESA' }
|
||||
)
|
||||
expect(http.delete).toHaveBeenCalledWith(
|
||||
'http://backend.test/don_confiao/api/municipalities/7/'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user