-
-
Notifications
You must be signed in to change notification settings - Fork 127
chore: fix codeql config #1915
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
chore: fix codeql config #1915
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| paths: | ||
| - 'packages' | ||
| paths-ignore: | ||
| - '**/*.test.js' | ||
| - '**/*.test.ts' | ||
| - '**/*.test.tsx' | ||
| - '**/__tests__/**' | ||
| - 'packages/ide/**' |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { loadSchema } from '@zenstackhq/testtools'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| describe('issue 1898', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| it('regression', async () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { enhance, prisma } = await loadSchema( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model Role { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id Int @id @default(autoincrement()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name String @unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions Permission[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foos Foo[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deletable Boolean @default(true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @@allow('all', true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model Permission { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id Int @id @default(autoincrement()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name String | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| roleId Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role Role @relation(fields: [roleId], references: [id], onDelete: Cascade) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @@allow('all', true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model Foo { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id Int @id @default(autoincrement()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name String | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| roleId Int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| role Role @relation(fields: [roleId], references: [id]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| `, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { logPrismaQuery: true, prismaClientOptions: { log: ['query', 'info'] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const db = enhance(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const role = await prisma.role.create({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| data: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'regular', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| create: [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: 1, name: 'read' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { id: 2, name: 'write' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const role = await prisma.role.create({ | |
| data: { | |
| name: 'regular', | |
| permissions: { | |
| create: [ | |
| { id: 1, name: 'read' }, | |
| { id: 2, name: 'write' }, | |
| ], | |
| }, | |
| }, | |
| }); | |
| const role = await prisma.role.create({ | |
| data: { | |
| name: 'regular', | |
| permissions: { | |
| create: [ | |
| { name: 'read' }, | |
| { name: 'write' }, | |
| ], | |
| }, | |
| }, | |
| include: { permissions: true }, | |
| }); | |
| expect(role.name).toBe('regular'); | |
| expect(role.permissions).toHaveLength(2); | |
| expect(role.permissions.map(p => p.name)).toEqual(['read', 'write']); |
Outdated
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.
🛠️ Refactor suggestion
Simplify complex update operation and fix logical issues
Several issues with the update operation:
- Using hardcoded ID (
id: 3) for new permission - Attempting to update a permission in the same transaction as its creation
- Complex operation mixing multiple concerns
Consider splitting this into multiple test cases or at least multiple operations:
const updatedRole = await prisma.role.update({
where: { id: role.id },
data: {
name: 'admin',
foos: {
create: { name: 'foo1' },
},
permissions: {
deleteMany: {
roleId: role.id,
},
- create: { id: 3, name: 'delete' },
- update: { where: { id: 3 }, data: { name: 'delete1' } },
+ create: { name: 'delete' },
},
deletable: false,
},
include: { permissions: true },
});
+expect(updatedRole.name).toBe('admin');
+expect(updatedRole.permissions).toHaveLength(1);
+expect(updatedRole.permissions[0].name).toBe('delete');📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const updatedRole = await prisma.role.update({ | |
| where: { id: role.id }, | |
| data: { | |
| name: 'admin', | |
| foos: { | |
| create: { name: 'foo1' }, | |
| }, | |
| permissions: { | |
| deleteMany: { | |
| roleId: role.id, | |
| }, | |
| create: { id: 3, name: 'delete' }, | |
| update: { where: { id: 3 }, data: { name: 'delete1' } }, | |
| }, | |
| deletable: false, | |
| }, | |
| include: { permissions: true }, | |
| }); | |
| const updatedRole = await prisma.role.update({ | |
| where: { id: role.id }, | |
| data: { | |
| name: 'admin', | |
| foos: { | |
| create: { name: 'foo1' }, | |
| }, | |
| permissions: { | |
| deleteMany: { | |
| roleId: role.id, | |
| }, | |
| create: { name: 'delete' }, | |
| }, | |
| deletable: false, | |
| }, | |
| include: { permissions: true }, | |
| }); | |
| expect(updatedRole.name).toBe('admin'); | |
| expect(updatedRole.permissions).toHaveLength(1); | |
| expect(updatedRole.permissions[0].name).toBe('delete'); |
Outdated
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.
Replace console.log with proper assertions
Using console.log is not a proper way to verify test results. Add explicit assertions to validate the expected state.
-console.log(updatedRole);
+expect(updatedRole).toMatchObject({
+ name: 'admin',
+ deletable: false,
+ permissions: expect.arrayContaining([
+ expect.objectContaining({ name: 'delete' })
+ ])
+});Committable suggestion skipped: line range outside the PR's diff.
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.
Add missing access rules for Foo model
The
Foomodel is missing access rules (@@allow) that are present in other models. This inconsistency might affect test behavior.model Foo { id Int @id @default(autoincrement()) name String roleId Int role Role @relation(fields: [roleId], references: [id]) + @@allow('all', true) }📝 Committable suggestion