Skip to content

Add custom rule integration and RQBv2 custom success-path tests #56

Description

@benvinegar

Summary

Custom defineScopedTable(...) rules have only fake-builder success coverage, and custom RQBv2 relational support has failure coverage but no success-path coverage. Add integration/unit tests for composite custom rules, RQBv2 custom object-filter support, and custom error factory arguments.

Evidence

Relevant APIs:

  • defineScopedTable(...) in src/rules.ts
  • ScopedTableRule.relational.rqbV2 in src/types.ts
  • RQBv2 merge/validation in src/internal/relational/rqb-v2-adapter.ts

Current tests:

  • fake-builder unit test for a composite custom rule;
  • unit test that custom RQBv2 rules without object-filter support throw;
  • custom error test checks full arguments for missingWhere, but not every error factory argument shape.

Suggested tests

Real-driver composite custom rule

For Postgres and SQLite, define a rule scoped by { workspaceId, regionId }:

defineScopedTable(projects, {
  where: (scope) => and(
    eq(projects.workspaceId, scope.workspaceId),
    eq(projects.regionId, scope.regionId),
  ),
  validateInsert: (row, scope) =>
    row.workspaceId === scope.workspaceId && row.regionId === scope.regionId,
  validateUpdate: (payload, scope) =>
    (!payload.workspaceId || payload.workspaceId === scope.workspaceId) &&
    (!payload.regionId || payload.regionId === scope.regionId),
  hasScopeInWhere: ...,
});

Assert real select/update/delete/upsert affect only rows matching both dimensions.

RQBv2 custom success path

Unit or integration where supported:

defineScopedTable(projects, {
  queryName: "projectsTbl",
  where: ...,
  relational: {
    rqbV2: {
      where: (scope) => ({ workspaceId: scope.workspaceId, regionId: scope.regionId }),
      hasScopeInWhere: (where) => /* require both keys */,
    },
  },
});

Assert:

  • strict missing composite scope throws;
  • valid object filter merges as { AND: [userWhere, scopedWhere] };
  • returned rows are scoped correctly where integration is available.

Error factory arguments

Add assertions that custom factories receive correct values:

  • invalidInsert(tableName, offendingRow, scopeName, scopeValue)
  • invalidUpdate(tableName, offendingPayload, scopeName, scopeValue)
  • invalidConflictTarget(tableName, scopeName, scopeValue)
  • missingScope(tableName, scopeName, scopeValue)

Acceptance criteria

  • Custom rule behavior is proven against at least one real driver.
  • RQBv2 custom object-filter success path is covered.
  • Error factory argument contracts are fully tested.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions