-
Notifications
You must be signed in to change notification settings - Fork 27
Add filters to deleteEntry #351
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a4cf14
Add filters to deleteEntry
stepanenkoxx 12bebf3
Add filters to deleteEntry
stepanenkoxx 0d8607a
Merge branch 'main' into DLAPI-500-add-filters-to-delete-entry
stepanenkoxx 631023d
Review fixes
stepanenkoxx a6737a4
Add tests
stepanenkoxx 10c0156
Add tests
stepanenkoxx 68d967b
Fix
stepanenkoxx 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
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,8 @@ | ||
| import {z} from 'zod'; | ||
|
|
||
| export const stringArray = ({min = 0, max = Infinity}: {min?: number; max?: number}) => { | ||
| return z | ||
| .union([z.string(), z.array(z.string())]) | ||
| .transform((val) => (typeof val === 'string' ? [val] : val)) | ||
| .pipe(z.array(z.string()).min(min).max(max)); | ||
| }; |
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
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
118 changes: 118 additions & 0 deletions
118
src/tests/int/env/opensource/suites/entries/delete-entry.test.ts
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,118 @@ | ||
| import request from 'supertest'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add tests to /env/platform/suites/... also? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
|
|
||
| import {routes} from '../../../../routes'; | ||
| import {app, auth} from '../../auth'; | ||
| import {createMockWorkbook, createMockWorkbookEntry} from '../../helpers'; | ||
| import {OpensourceRole} from '../../roles'; | ||
|
|
||
| let workbookId: string; | ||
| let workbookEntryId: string; | ||
|
|
||
| const notExistingEntryId = 'fvsb9zbfkqos2'; | ||
|
|
||
| describe('Delete entry', () => { | ||
| test('[Setup test data] Create workbook and entry for deletion', async () => { | ||
| const workbook = await createMockWorkbook({title: 'Workbook for deletion'}); | ||
| workbookId = workbook.workbookId; | ||
|
|
||
| const workbookEntry = await createMockWorkbookEntry({ | ||
| name: 'Entry for deletion', | ||
| workbookId: workbook.workbookId, | ||
| scope: 'dash', | ||
| type: 'wizard-widget', | ||
| }); | ||
|
|
||
| workbookEntryId = workbookEntry.entryId; | ||
| }); | ||
|
|
||
| test('Delete entry without auth error', async () => { | ||
| await request(app).delete(`${routes.entries}/${workbookEntryId}`).expect(401); | ||
| }); | ||
|
|
||
| test('Delete non-existing entry error', async () => { | ||
| await auth(request(app).delete(`${routes.entries}/${notExistingEntryId}`), { | ||
| role: OpensourceRole.Editor, | ||
| }).expect(404); | ||
| }); | ||
|
|
||
| test('Delete entry with read-only permissions error', async () => { | ||
| await auth(request(app).delete(`${routes.entries}/${workbookEntryId}`), { | ||
| role: OpensourceRole.Viewer, | ||
| }).expect(403); | ||
| }); | ||
|
|
||
| test('Delete entry with wrong filter by scope. Entry is not found', async () => { | ||
| await auth( | ||
| request(app).delete(`${routes.entries}/${workbookEntryId}`).query({ | ||
| scope: 'dataset', | ||
| }), | ||
| { | ||
| role: OpensourceRole.Editor, | ||
| }, | ||
| ).expect(404); | ||
| }); | ||
|
|
||
| test('Delete entry with wrong filter by types. Entry is not found', async () => { | ||
| await auth( | ||
| request(app) | ||
| .delete(`${routes.entries}/${workbookEntryId}`) | ||
| .query({ | ||
| types: ['wizard-chart', 'wizard-node'], | ||
| }), | ||
| { | ||
| role: OpensourceRole.Editor, | ||
| }, | ||
| ).expect(404); | ||
| }); | ||
|
|
||
| test('Successfully delete entry with filters by scope and types', async () => { | ||
| const newEntry = await createMockWorkbookEntry({ | ||
| name: 'Entry for scope and types test', | ||
| workbookId: workbookId, | ||
| scope: 'dash', | ||
| type: 'wizard-widget', | ||
| }); | ||
|
|
||
| const response = await auth( | ||
| request(app) | ||
| .delete(`${routes.entries}/${newEntry.entryId}`) | ||
| .query({ | ||
| scope: 'dash', | ||
| types: ['wizard-widget'], | ||
| }), | ||
| { | ||
| role: OpensourceRole.Editor, | ||
| }, | ||
| ).expect(200); | ||
|
|
||
| expect(response.body.isDeleted).toBe(true); | ||
| }); | ||
|
|
||
| test('Successfully delete entry', async () => { | ||
| const response = await auth(request(app).delete(`${routes.entries}/${workbookEntryId}`), { | ||
| role: OpensourceRole.Editor, | ||
| }).expect(200); | ||
|
|
||
| expect(response.body.isDeleted).toBe(true); | ||
|
|
||
| await auth(request(app).get(`${routes.entries}/${workbookEntryId}`), { | ||
| role: OpensourceRole.Editor, | ||
| }).expect(404); | ||
| }); | ||
|
|
||
| test('Recover deleted entry', async () => { | ||
| const response = await auth(request(app).post(`${routes.entries}/${workbookEntryId}`), { | ||
| role: OpensourceRole.Editor, | ||
| }) | ||
| .send({ | ||
| mode: 'recover', | ||
| }) | ||
| .expect(200); | ||
|
|
||
| expect(response.body.isDeleted).toBeFalsy(); | ||
|
|
||
| await auth(request(app).get(`${routes.entries}/${workbookEntryId}`), { | ||
| role: OpensourceRole.Editor, | ||
| }).expect(200); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Is it work good without index on entries.type
I know that we also don't have index on isDeleted but it's boolean
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.
It makes index scan on entryId and then filters the result, it's 1 row maximum
https://explain.tensor.ru/archive/explain/69ee14e376c7bbf98863ee3c2327e878:0:2025-09-16