Skip to content

Commit da4189b

Browse files
committed
fix: throw when store name is missing
1 parent a028e34 commit da4189b

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/main.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,4 +1100,24 @@ describe(`getStore`, () => {
11001100
}),
11011101
).toThrowError(MissingBlobsEnvironmentError)
11021102
})
1103+
1104+
test('Throws when the name of the store is not provided', async () => {
1105+
const { fetch } = new MockFetch()
1106+
1107+
globalThis.fetch = fetch
1108+
1109+
// @ts-expect-error Ignoring types, which expect an argument
1110+
expect(() => getStore()).toThrowError(
1111+
'The `getStore` method requires the name of the store as a string or as the `name` property of an options object',
1112+
)
1113+
1114+
expect(() =>
1115+
getStore({
1116+
token: apiToken,
1117+
siteID,
1118+
}),
1119+
).toThrowError(
1120+
'The `getStore` method requires the name of the store as a string or as the `name` property of an options object',
1121+
)
1122+
})
11031123
})

src/store_factory.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const getStore: {
4444
return new Store({ client, name: input })
4545
}
4646

47-
if (typeof input.name === 'string') {
47+
if (typeof input?.name === 'string') {
4848
const { name } = input
4949
const clientOptions = getClientOptions(input)
5050

@@ -57,7 +57,7 @@ export const getStore: {
5757
return new Store({ client, name })
5858
}
5959

60-
if (typeof input.deployID === 'string') {
60+
if (typeof input?.deployID === 'string') {
6161
const clientOptions = getClientOptions(input)
6262
const { deployID } = input
6363

@@ -70,5 +70,7 @@ export const getStore: {
7070
return new Store({ client, deployID })
7171
}
7272

73-
throw new Error('`getStore()` requires a `name` or `siteID` properties.')
73+
throw new Error(
74+
'The `getStore` method requires the name of the store as a string or as the `name` property of an options object',
75+
)
7476
}

0 commit comments

Comments
 (0)