-
Notifications
You must be signed in to change notification settings - Fork 2.5k
test: add coverage for StorageTable.is and StorageTable.assert #30204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
EmaToplek
wants to merge
1
commit into
prisma:main
Choose a base branch
from
EmaToplek:test/contract-storage-table-coverage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { StorageTable } from '../src/ir/storage-table'; | ||
|
|
||
| function makeValidTable(): StorageTable { | ||
| return new StorageTable({ | ||
| columns: { | ||
| id: { codecId: 'pg/int4@1', nativeType: 'int4', nullable: false }, | ||
| }, | ||
| uniques: [], | ||
| indexes: [], | ||
| foreignKeys: [], | ||
| }); | ||
| } | ||
|
|
||
| describe('StorageTable.is', () => { | ||
| it('returns true for a real StorageTable instance', () => { | ||
| expect(StorageTable.is(makeValidTable())).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for a duck-typed plain object with all required keys', () => { | ||
| const ducked = { | ||
| columns: {}, | ||
| uniques: [], | ||
| indexes: [], | ||
| foreignKeys: [], | ||
| } as unknown as StorageTable; | ||
| expect(StorageTable.is(ducked)).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for undefined', () => { | ||
| expect(StorageTable.is(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for null', () => { | ||
| expect(StorageTable.is(null as unknown as StorageTable)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for a non-object primitive', () => { | ||
| expect(StorageTable.is('not-a-table' as unknown as StorageTable)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when columns is missing', () => { | ||
| const missingColumns = { | ||
| uniques: [], | ||
| indexes: [], | ||
| foreignKeys: [], | ||
| } as unknown as StorageTable; | ||
| expect(StorageTable.is(missingColumns)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when uniques is missing', () => { | ||
| const missingUniques = { | ||
| columns: {}, | ||
| indexes: [], | ||
| foreignKeys: [], | ||
| } as unknown as StorageTable; | ||
| expect(StorageTable.is(missingUniques)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when indexes is missing', () => { | ||
| const missingIndexes = { | ||
| columns: {}, | ||
| uniques: [], | ||
| foreignKeys: [], | ||
| } as unknown as StorageTable; | ||
| expect(StorageTable.is(missingIndexes)).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when foreignKeys is missing', () => { | ||
| const missingForeignKeys = { | ||
| columns: {}, | ||
| uniques: [], | ||
| indexes: [], | ||
| } as unknown as StorageTable; | ||
| expect(StorageTable.is(missingForeignKeys)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('StorageTable.assert', () => { | ||
| it('does not throw for a real StorageTable instance', () => { | ||
| expect(() => StorageTable.assert(makeValidTable(), 'test.coordinate')).not.toThrow(); | ||
| }); | ||
|
|
||
| it('throws InternalError naming the coordinate when the value is not a StorageTable', () => { | ||
| expect(() => StorageTable.assert(undefined, 'namespaces.public.table.users')).toThrow( | ||
| /Expected a StorageTable at namespaces\.public\.table\.users/, | ||
| ); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🤖 get_repo_knowledge executed:
get_repo_knowledge prisma/orm /tmp/coderabbit-repo-knowledge/prisma-orm-2af69ac7/learnings /tmp/coderabbit-repo-knowledge/prisma-orm-2af69ac7/conventionsLength of output: 29025
🏁 Script executed:
Repository: prisma/orm
Length of output: 7509
Assert the
InternalErrorclass.StorageTable.assertthrowsInternalError, but the current matcher checks only the message. Assert the error class and retain the coordinate message assertion.🤖 Prompt for AI Agents