Skip to content

Commit c57a951

Browse files
committed
test(plugin-auth): route the fake engine's update through the dispatch assert
Claude-Session: https://claude.ai/code/session_019srGWGCBBCBHqcDoRZpQRh Co-authored-by: Claude <noreply@anthropic.com>
1 parent e89c3b2 commit c57a951

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎packages/plugins/plugin-auth/src/organization-metadata-decode.test.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { describe, it, expect, vi } from 'vitest';
2727
import type { IDataEngine } from '@objectstack/core';
2828
import { SystemObjectName } from '@objectstack/spec/system';
2929
import { organization } from 'better-auth/plugins/organization';
30+
import { assertEngineUpdateDispatch } from '@objectstack/objectql';
3031
import { decodeOrganizationMetadataOnRead } from './organization-metadata-decode.js';
3132
import { createObjectQLAdapterFactory } from './objectql-adapter.js';
3233
import { buildOrganizationPluginSchema } from './auth-schema-config.js';
@@ -101,7 +102,12 @@ describe('⭐ the four read routes serve the decoded object, through the real ad
101102
findOne: vi.fn().mockResolvedValue(row ? { ...row } : null),
102103
find: vi.fn().mockResolvedValue(row ? [{ ...row }] : []),
103104
count: vi.fn().mockResolvedValue(0),
104-
update: vi.fn().mockImplementation((_m: string, d: any) => Promise.resolve({ ...STORED_ROW, ...d })),
105+
update: vi.fn().mockImplementation((_m: string, d: any, options?: any) => {
106+
// The real engine's three-way dispatch — a double looser than this is
107+
// no double at all (`check:engine-double-contract`).
108+
assertEngineUpdateDispatch(d, options);
109+
return Promise.resolve({ ...STORED_ROW, ...d });
110+
}),
105111
delete: vi.fn().mockResolvedValue(undefined),
106112
} as unknown as IDataEngine;
107113
// The plugin must be mounted: better-auth's factory validates the model

‎scripts/engine-double-contract.pinned.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,6 +2606,11 @@
26062606
"verb": "update",
26072607
"pinned": 1
26082608
},
2609+
{
2610+
"file": "packages/plugins/plugin-auth/src/organization-metadata-decode.test.ts",
2611+
"verb": "update",
2612+
"pinned": 1
2613+
},
26092614
{
26102615
"file": "packages/plugins/plugin-auth/src/remove-member-permission-guard.test.ts",
26112616
"verb": "delete",

0 commit comments

Comments
 (0)