1
+ const consumers = require ( 'node:stream/consumers' )
2
+
1
3
const { gql } = require ( '../util' )
2
4
3
5
const _toBase64Url = value => value . replace ( / \/ / g, '_' ) . replace ( / \+ / g, '-' )
4
6
5
- const _getTestBuffer = length => {
6
- const testString = 'Test String! '
7
- let string = testString . repeat ( Math . ceil ( length / testString . length ) ) . slice ( 0 , length )
8
- return Buffer . from ( string )
7
+ const _getTestString = length => {
8
+ const testString = 'This is a test string! '
9
+ return testString . repeat ( Math . ceil ( length / testString . length ) ) . slice ( 0 , length )
9
10
}
10
11
12
+ const _getTestBuffer = length => Buffer . from ( _getTestString ( length ) )
13
+
14
+ // e.g. base64 string with length 96 -> requires buffer with length 72
15
+ const _neededBufferLengthForBase64StringWithLength = length => Math . ceil ( ( length * 6 ) / 8 )
16
+
11
17
const _getMutationForFieldWithLiteralValue = ( field , value , quoted ) => ( {
12
18
query : gql `
13
19
mutation {
@@ -48,9 +54,7 @@ describe('graphql - types parsing and validation', () => {
48
54
// Prevent axios from throwing errors for non 2xx status codes
49
55
axios . defaults . validateStatus = false
50
56
51
- beforeEach ( async ( ) => {
52
- await data . reset ( )
53
- } )
57
+ beforeEach ( data . reset )
54
58
55
59
describe ( 'cds.Binary' , ( ) => {
56
60
const field = 'myBinary'
@@ -1002,12 +1006,9 @@ describe('graphql - types parsing and validation', () => {
1002
1006
} )
1003
1007
1004
1008
// Note: maps to same type as cds.Binary
1005
- // REVISIT: express-graphql limits request body size to 100kb by default:
1006
- // - https://github.com/graphql/express-graphql/issues/346
1007
- // - https://github.com/graphql/express-graphql/blob/28e4c2924ea6984bf918465cefdadae340d8780e/src/parseBody.ts#L96
1008
- describe . skip ( 'cds.LargeBinary' , ( ) => {
1009
+ describe ( 'cds.LargeBinary' , ( ) => {
1009
1010
const field = 'myLargeBinary'
1010
- const buffer = _getTestBuffer ( 500000 ) // 500 KB
1011
+ const buffer = _getTestBuffer ( _neededBufferLengthForBase64StringWithLength ( 105000 ) ) // 105 KB as base64 string
1011
1012
1012
1013
describe ( 'input literal' , ( ) => {
1013
1014
test ( 'cds.LargeBinary is correctly parsed from large input literal base64 encoded string value' , async ( ) => {
@@ -1018,7 +1019,8 @@ describe('graphql - types parsing and validation', () => {
1018
1019
expect ( response . data ) . toEqual ( { data } )
1019
1020
1020
1021
const result = await SELECT . one . from ( 'sap.cds.graphql.types.MyEntity' ) . columns ( field )
1021
- expect ( result [ field ] ) . toEqual ( buffer )
1022
+ const bufferFromDB = await consumers . buffer ( result [ field ] )
1023
+ expect ( bufferFromDB ) . toEqual ( buffer )
1022
1024
} )
1023
1025
1024
1026
test ( 'cds.LargeBinary is correctly parsed from large input literal base64url encoded string value' , async ( ) => {
@@ -1029,7 +1031,8 @@ describe('graphql - types parsing and validation', () => {
1029
1031
expect ( response . data ) . toEqual ( { data } )
1030
1032
1031
1033
const result = await SELECT . one . from ( 'sap.cds.graphql.types.MyEntity' ) . columns ( field )
1032
- expect ( result [ field ] ) . toEqual ( buffer )
1034
+ const bufferFromDB = await consumers . buffer ( result [ field ] )
1035
+ expect ( bufferFromDB ) . toEqual ( buffer )
1033
1036
} )
1034
1037
} )
1035
1038
@@ -1042,7 +1045,8 @@ describe('graphql - types parsing and validation', () => {
1042
1045
expect ( response . data ) . toEqual ( { data } )
1043
1046
1044
1047
const result = await SELECT . one . from ( 'sap.cds.graphql.types.MyEntity' ) . columns ( field )
1045
- expect ( result [ field ] ) . toEqual ( buffer )
1048
+ const bufferFromDB = await consumers . buffer ( result [ field ] )
1049
+ expect ( bufferFromDB ) . toEqual ( buffer )
1046
1050
} )
1047
1051
1048
1052
test ( 'cds.LargeBinary is correctly parsed from large variable base64url encoded string value' , async ( ) => {
@@ -1053,18 +1057,16 @@ describe('graphql - types parsing and validation', () => {
1053
1057
expect ( response . data ) . toEqual ( { data } )
1054
1058
1055
1059
const result = await SELECT . one . from ( 'sap.cds.graphql.types.MyEntity' ) . columns ( field )
1056
- expect ( result [ field ] ) . toEqual ( buffer )
1060
+ const bufferFromDB = await consumers . buffer ( result [ field ] )
1061
+ expect ( bufferFromDB ) . toEqual ( buffer )
1057
1062
} )
1058
1063
} )
1059
1064
} )
1060
1065
1061
1066
// Note: maps to same type as cds.String
1062
- // REVISIT: express-graphql limits request body size to 100kb by default:
1063
- // - https://github.com/graphql/express-graphql/issues/346
1064
- // - https://github.com/graphql/express-graphql/blob/28e4c2924ea6984bf918465cefdadae340d8780e/src/parseBody.ts#L96
1065
- describe . skip ( 'cds.LargeString' , ( ) => {
1067
+ describe ( 'cds.LargeString' , ( ) => {
1066
1068
const field = 'myLargeString'
1067
- const value = 'This is a test string! ' . repeat ( 100000 )
1069
+ const value = _getTestString ( 105000 ) // 105 KB
1068
1070
1069
1071
test ( 'cds.LargeString is correctly parsed from input literal' , async ( ) => {
1070
1072
const body = _getMutationForFieldWithLiteralValue ( field , value , true )
0 commit comments