fix(docsync): a paused binding no longer resets its own settings

PATCH links validated its body with a schema derived from the create
contract through .partial(). In Zod 4 a .default() still fires inside an
optional field, so a patch naming one setting arrived with every other
one filled in: pausing a pull-only binding switched it to two-way, reset
both policies and blanked its label. The update contract is now written
out without defaults, and an e2e test drives a patch through the real
pipe, which the controller unit tests never see.

Also, the cosmetic leftovers from the review:
- POST connections/:connectionId/scopes no longer wants the connection
  in the body as well. It was required, never read, and let one request
  name two connections; a client that still sends it has the key
  stripped rather than refused.
- createLink loses the scope argument every caller passed as null.
- The controller's owner check is now assertCanManage, because it lets
  instance admins through just as canManageDocSync does on the client.
  Who may manage a binding is unchanged.
- document_provider_fields drops settings_key and payload_key. Nothing
  read them: the connect form takes its fields from /docsync/providers
  and the admin shelf sends none for document providers.
- The e2e test imports the provider classes under their new names.
This commit is contained in:
Maurice
2026-09-19 12:06:06 +02:00
parent 01a7224f29
commit b88b92add7
11 changed files with 243 additions and 71 deletions
@@ -440,14 +440,24 @@ describe('the scope picker', () => {
data: { scopeKey: 'tag:9', label: 'Norway', remoteRootId: '9', remoteRootPath: '/TREK/norway' },
} as never);
await expect(controller.createScope(String(tripId), String(conn.id), owner, { connectionId: conn.id, name: 'Norway' }))
await expect(controller.createScope(String(tripId), String(conn.id), owner, { name: 'Norway' }))
.resolves.toMatchObject({ scopeKey: 'tag:9', label: 'Norway' });
expect(paperless.createScope).toHaveBeenCalledWith(expect.objectContaining({ connectionId: conn.id }), 'Norway');
});
it('creates nothing through a connection that belongs to a different trip', async () => {
// The connection comes from the path and nowhere else, so the path is what
// has to match the trip the caller was admitted to.
const conn = await storedPaperless();
const err = await thrown(() => controller.createScope(String(otherTripId), String(conn.id), admin, { name: 'Norway' }));
expect(err.getStatus()).toBe(404);
expect(paperless.createScope).not.toHaveBeenCalled();
});
it('turns a refused creation into a 400 carrying the provider code', async () => {
const conn = await storedPaperless();
paperless.createScope.mockResolvedValueOnce({ success: false, error: { code: 'forbidden' } } as never);
const err = await thrown(() => controller.createScope(String(tripId), String(conn.id), owner, { connectionId: conn.id, name: 'Norway' }));
const err = await thrown(() => controller.createScope(String(tripId), String(conn.id), owner, { name: 'Norway' }));
expect(err.getStatus()).toBe(400);
expect(err.message).toBe('forbidden');
});
@@ -695,9 +705,9 @@ describe('a manual run and the shelved rows', () => {
/**
* The trip the route was authorised against is now passed on to the service.
*
* `assertOwner` proves the caller owns the trip in the URL and says nothing
* about whether the item id in the path belongs to that trip — the id is a
* plain integer, and nothing tied the two together. The check itself lives in
* `assertCanManage` proves the caller may manage the trip in the URL and says
* nothing about whether the item id in the path belongs to that trip: the id is
* a plain integer, and nothing tied the two together. The check itself lives in
* the service (where the row is), so what belongs here is that the trip reaches
* it at all.
*/