mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-28 01:22:41 -05:00
Enhancement: use patch instead of put for frontend document changes (#9744)
This commit is contained in:
@@ -456,11 +456,11 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
component.title = 'Foo Bar'
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
updateSpy.mockImplementation((o) => of(doc))
|
||||
patchSpy.mockImplementation((o) => of(doc))
|
||||
component.save(true)
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalledWith(
|
||||
'Document "Doc 3" saved successfully.'
|
||||
@@ -471,11 +471,11 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
component.title = 'Foo Bar'
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
updateSpy.mockImplementation((o) => of(doc))
|
||||
patchSpy.mockImplementation((o) => of(doc))
|
||||
component.save()
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(closeSpy).not.toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalledWith(
|
||||
'Document "Doc 3" saved successfully.'
|
||||
@@ -487,12 +487,12 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
component.title = 'Foo Bar'
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
const toastSpy = jest.spyOn(toastService, 'showError')
|
||||
const error = new Error('failed to save')
|
||||
updateSpy.mockImplementation(() => throwError(() => error))
|
||||
patchSpy.mockImplementation(() => throwError(() => error))
|
||||
component.save()
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(closeSpy).not.toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalledWith(
|
||||
'Error saving document "Doc 3"',
|
||||
@@ -505,13 +505,13 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
component.title = 'Foo Bar'
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
const toastSpy = jest.spyOn(toastService, 'showInfo')
|
||||
updateSpy.mockImplementation(() =>
|
||||
patchSpy.mockImplementation(() =>
|
||||
throwError(() => new Error('failed to save'))
|
||||
)
|
||||
component.save(true)
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalledWith(
|
||||
'Document "Doc 3" saved successfully.'
|
||||
@@ -522,8 +522,8 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
const nextDocId = 100
|
||||
component.title = 'Foo Bar'
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
updateSpy.mockReturnValue(of(doc))
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
patchSpy.mockReturnValue(of(doc))
|
||||
const nextSpy = jest.spyOn(documentListViewService, 'getNext')
|
||||
nextSpy.mockReturnValue(of(nextDocId))
|
||||
const closeSpy = jest.spyOn(openDocumentsService, 'closeDocument')
|
||||
@@ -531,7 +531,7 @@ describe('DocumentDetailComponent', () => {
|
||||
const navigateSpy = jest.spyOn(router, 'navigate')
|
||||
|
||||
component.saveEditNext()
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(navigateSpy).toHaveBeenCalledWith(['documents', nextDocId])
|
||||
expect
|
||||
})
|
||||
@@ -541,12 +541,12 @@ describe('DocumentDetailComponent', () => {
|
||||
initNormally()
|
||||
component.title = 'Foo Bar'
|
||||
const closeSpy = jest.spyOn(component, 'close')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
const toastSpy = jest.spyOn(toastService, 'showError')
|
||||
const error = new Error('failed to save')
|
||||
updateSpy.mockImplementation(() => throwError(() => error))
|
||||
patchSpy.mockImplementation(() => throwError(() => error))
|
||||
component.saveEditNext()
|
||||
expect(updateSpy).toHaveBeenCalled()
|
||||
expect(patchSpy).toHaveBeenCalled()
|
||||
expect(closeSpy).not.toHaveBeenCalled()
|
||||
expect(toastSpy).toHaveBeenCalledWith('Error saving document', error)
|
||||
})
|
||||
@@ -965,10 +965,10 @@ describe('DocumentDetailComponent', () => {
|
||||
expect(fixture.debugElement.nativeElement.textContent).toContain(
|
||||
customFields[1].name
|
||||
)
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
component.save(true)
|
||||
expect(updateSpy.mock.lastCall[0].custom_fields).toHaveLength(2)
|
||||
expect(updateSpy.mock.lastCall[0].custom_fields[1]).toEqual({
|
||||
expect(patchSpy.mock.lastCall[0].custom_fields).toHaveLength(2)
|
||||
expect(patchSpy.mock.lastCall[0].custom_fields[1]).toEqual({
|
||||
field: customFields[1].id,
|
||||
value: null,
|
||||
})
|
||||
@@ -985,9 +985,9 @@ describe('DocumentDetailComponent', () => {
|
||||
expect(
|
||||
fixture.debugElement.query(By.css('form')).nativeElement.textContent
|
||||
).not.toContain('Field 1')
|
||||
const updateSpy = jest.spyOn(documentService, 'update')
|
||||
const patchSpy = jest.spyOn(documentService, 'patch')
|
||||
component.save(true)
|
||||
expect(updateSpy.mock.lastCall[0].custom_fields).toHaveLength(
|
||||
expect(patchSpy.mock.lastCall[0].custom_fields).toHaveLength(
|
||||
initialLength - 1
|
||||
)
|
||||
})
|
||||
|
Reference in New Issue
Block a user