Skip to content

Commit 5926626

Browse files
committed
feat(configuration-validation): test that indexName is an array
instead of a string
1 parent 9aa1254 commit 5926626

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

server/__tests__/configuration-validation.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Test plugin configuration', () => {
113113
expect(strapiMock.log.error).toHaveBeenCalledTimes(0)
114114
})
115115

116-
test('Test indexName with empty string', async () => {
116+
test('Test indexName with string', async () => {
117117
validatePluginConfig({
118118
restaurant: {
119119
indexName: '',
@@ -122,14 +122,14 @@ describe('Test plugin configuration', () => {
122122
expect(strapiMock.log.warn).toHaveBeenCalledTimes(0)
123123
expect(strapiMock.log.error).toHaveBeenCalledTimes(1)
124124
expect(strapiMock.log.error).toHaveBeenCalledWith(
125-
'The "indexName" option of "restaurant" should be a non-empty string',
125+
'The "indexName" option of "restaurant" should be a non-empty array of strings',
126126
)
127127
})
128128

129-
test('Test indexName with non-empty string', async () => {
129+
test('Test indexName with non-empty array', async () => {
130130
validatePluginConfig({
131131
restaurant: {
132-
indexName: 'hello',
132+
indexName: ['hello'],
133133
},
134134
})
135135
expect(strapiMock.log.warn).toHaveBeenCalledTimes(0)

server/configuration-validation.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,10 @@ function CollectionConfig({ collectionName, configuration }) {
182182

183183
return {
184184
validateIndexName() {
185-
// indexName is either undefined or a none empty string
186-
if (
187-
(indexName !== undefined && typeof indexName !== 'string') ||
188-
indexName === ''
189-
) {
185+
// indexName is either undefined or a non empty array of string
186+
if (indexName !== undefined && !Array.isArray(indexName)) {
190187
log.error(
191-
`The "indexName" option of "${collectionName}" should be a non-empty string`,
188+
`The "indexName" option of "${collectionName}" should be a non-empty array of strings`,
192189
)
193190
} else if (indexName !== undefined) {
194191
options.indexName = indexName

0 commit comments

Comments
 (0)