-
Notifications
You must be signed in to change notification settings - Fork 406
#RI-4815 get a portion of the string #2685
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
irinaAbramova-dev
merged 6 commits into
feature/RI-4815-portion-of-string
from
be/feature/RI-4815-portion-of-string
Oct 17, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cef594c
#RI-4815 get a portion of the string [skip ci]
irinaAbramova-dev 62e7068
#RI-4815 add tests
irinaAbramova-dev aba348f
#RI-4815 change implementation
irinaAbramova-dev 26e5350
#RI-4815 fix getting value
irinaAbramova-dev fa44880
#RI-4815 fix tests
irinaAbramova-dev 7836a03
#RI-4815 fix download string
irinaAbramova-dev 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
18 changes: 18 additions & 0 deletions
18
redisinsight/api/src/common/decorators/is-bigger-than.decorator.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,18 @@ | ||
import { | ||
registerDecorator, | ||
ValidationOptions, | ||
} from 'class-validator'; | ||
import { BiggerThan } from 'src/common/validators/bigger-than.validator'; | ||
|
||
export function IsBiggerThan(property: string, validationOptions?: ValidationOptions) { | ||
return (object: any, propertyName: string) => { | ||
registerDecorator({ | ||
name: 'IsBiggerThan', | ||
target: object.constructor, | ||
propertyName, | ||
constraints: [property], | ||
options: validationOptions, | ||
validator: BiggerThan, | ||
}); | ||
}; | ||
} | ||
18 changes: 18 additions & 0 deletions
18
redisinsight/api/src/common/validators/bigger-than.validator.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,18 @@ | ||
import { | ||
ValidationArguments, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from 'class-validator'; | ||
|
||
@ValidatorConstraint({ name: 'BiggerThan', async: true }) | ||
export class BiggerThan implements ValidatorConstraintInterface { | ||
validate(value: any, args: ValidationArguments) { | ||
const [relatedPropertyName] = args.constraints; | ||
const relatedValue = (args.object as any)[relatedPropertyName]; | ||
return typeof value === 'number' && typeof relatedValue === 'number' && value > relatedValue; | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
return `${args.property} must be bigger than ${args.constraints.join(', ')}`; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './redis-string.validator'; | ||
export * from './zset-score.validator'; | ||
export * from './multi-number.validator'; | ||
export * from './bigger-than.validator'; |
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
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
114 changes: 114 additions & 0 deletions
114
redisinsight/api/test/api/string/POST-databases-id-string-download_value.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,114 @@ | ||
import { | ||
describe, | ||
before, | ||
Joi, | ||
deps, | ||
requirements, | ||
generateInvalidDataTestCases, | ||
validateInvalidDataTestCase, | ||
getMainCheckFn | ||
} from '../deps' | ||
const { server, request, constants, rte } = deps; | ||
|
||
// endpoint to test | ||
const endpoint = (instanceId = constants.TEST_INSTANCE_ID) => | ||
request(server).post(`/${constants.API.DATABASES}/${instanceId}/string/download-value`); | ||
|
||
// input data schema | ||
const dataSchema = Joi.object({ | ||
keyName: Joi.string().allow('').required(), | ||
}).strict(); | ||
|
||
const validInputData = { | ||
keyName: constants.TEST_STRING_KEY_1, | ||
}; | ||
|
||
const mainCheckFn = getMainCheckFn(endpoint); | ||
|
||
describe('POST /databases/:instanceId/string/download-value', () => { | ||
describe('Main', () => { | ||
before(() => rte.data.generateBinKeys(true)); | ||
|
||
describe('Validation', () => { | ||
generateInvalidDataTestCases(dataSchema, validInputData).map( | ||
validateInvalidDataTestCase(endpoint, dataSchema), | ||
); | ||
}); | ||
|
||
describe('Common', () => { | ||
[ | ||
{ | ||
name: 'Should download value', | ||
data: { | ||
keyName: constants.TEST_STRING_KEY_BIN_BUF_OBJ_1, | ||
}, | ||
responseHeaders: { | ||
'content-type': 'application/octet-stream', | ||
'content-disposition': 'attachment;filename="string_value"', | ||
'access-control-expose-headers': 'Content-Disposition', | ||
}, | ||
responseBody: constants.TEST_STRING_VALUE_BIN_BUFFER_1, | ||
}, | ||
{ | ||
name: 'Should return an error when incorrect type', | ||
data: { | ||
keyName: constants.TEST_LIST_KEY_BIN_BUF_OBJ_1, | ||
}, | ||
statusCode: 400, | ||
responseBody: { | ||
statusCode: 400, | ||
error: 'Bad Request', | ||
}, | ||
}, | ||
{ | ||
name: 'Should return NotFound error if instance id does not exists', | ||
endpoint: () => endpoint(constants.TEST_NOT_EXISTED_INSTANCE_ID), | ||
data: { | ||
keyName: constants.TEST_STRING_KEY_BIN_BUF_OBJ_1, | ||
}, | ||
statusCode: 404, | ||
responseBody: { | ||
statusCode: 404, | ||
error: 'Not Found', | ||
message: 'Invalid database instance id.', | ||
}, | ||
}, | ||
].map(mainCheckFn); | ||
}); | ||
|
||
describe('ACL', () => { | ||
requirements('rte.acl'); | ||
before(async () => rte.data.setAclUserRules('~* +@all')); | ||
|
||
[ | ||
{ | ||
name: 'Should download value', | ||
endpoint: () => endpoint(constants.TEST_INSTANCE_ACL_ID), | ||
data: { | ||
keyName: constants.TEST_STRING_KEY_BIN_BUF_OBJ_1, | ||
}, | ||
responseHeaders: { | ||
'content-type': 'application/octet-stream', | ||
'content-disposition': 'attachment;filename="string_value"', | ||
'access-control-expose-headers': 'Content-Disposition', | ||
}, | ||
responseBody: constants.TEST_STRING_VALUE_BIN_BUFFER_1, | ||
}, | ||
{ | ||
name: 'Should throw error if no permissions for "set" command', | ||
endpoint: () => endpoint(constants.TEST_INSTANCE_ACL_ID), | ||
data: { | ||
keyName: constants.getRandomString(), | ||
value: constants.getRandomString(), | ||
}, | ||
statusCode: 403, | ||
responseBody: { | ||
statusCode: 403, | ||
error: 'Forbidden', | ||
}, | ||
before: () => rte.data.setAclUserRules('~* +@all -get') | ||
}, | ||
].map(mainCheckFn); | ||
}); | ||
}); | ||
}); |
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.
Uh oh!
There was an error while loading. Please reload this page.