Skip to content

Commit 46c93ae

Browse files
fix: check for duplicate proprerties
1 parent b9ec38e commit 46c93ae

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/features/upload-file/factories/strip-payload-factory.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,31 @@ describe('stripPayloadFactory', () => {
5353
[uploadOptions.properties.filesToDelete]: payload[uploadOptions.properties.filesToDelete],
5454
})
5555
})
56+
57+
it('throws error when user wants to use the same properties twice', async () => {
58+
try {
59+
await stripPayload({ payload, method: 'post' } as ActionRequest, actionContext)
60+
} catch (error) {
61+
expect(error).not.to.be.undefined
62+
return undefined
63+
}
64+
throw new Error()
65+
})
66+
67+
it('fills context with invocations for each run', async () => {
68+
uploadOptions = {
69+
...uploadOptions,
70+
properties: {
71+
key: 's3Key2',
72+
filePath: 'resolvedPath2',
73+
file: 'file2',
74+
filesToDelete: 'fileToDelete2',
75+
},
76+
}
77+
stripPayload = stripPayloadFactory(uploadOptions)
78+
await stripPayload({ payload, method: 'post' } as ActionRequest, actionContext)
79+
80+
expect(actionContext[CONTEXT_NAMESPACE].__invocations).to.have.lengthOf(2)
81+
})
5682
})
5783
})

src/features/upload-file/factories/strip-payload-factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ type ContextNamespace = {
1111
* `file` can be `myFile`
1212
*/
1313
[key: string]: any,
14+
/**
15+
* When we strip payload for each upload we are also storing use properties under __invocations
16+
* key. This is because in the next step we have to validate if all the properties are unique.
17+
* Otherwise upload from one element will override the upload in another element.
18+
*/
1419
__invocations: Array<FeatureInvocation>
1520
}
1621

@@ -30,7 +35,8 @@ export const stripPayloadFactory = (
3035
...data,
3136
[properties.file]: flat.get(request.payload, properties.file),
3237
[properties.filesToDelete]: flat.get(request.payload, properties.filesToDelete),
33-
__invocations: data.__invocations || [
38+
__invocations: [
39+
...(data.__invocations || []),
3440
{ properties },
3541
],
3642
}

src/features/upload-file/utils/validate-properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const hasDuplicatedProperties = (
3737
}
3838

3939
/**
40-
* Checks if all properties
40+
* Checks if all properties have uniq names
4141
*/
4242
export const validatePropertiesGlobally = (
4343
globalContext: Array<FeatureInvocation>,

0 commit comments

Comments
 (0)