Skip to content

Commit 01ddca2

Browse files
committed
pr feedback: remove isRemote() check in isDataStoreAvailable()
1 parent d17aadb commit 01ddca2

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

packages/pwa-kit-runtime/src/utils/ssr-server/data-store.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import {isRemote, logMRTError} from './utils'
7+
import {logMRTError} from './utils'
88

99
export class DataStoreNotFoundError extends Error {
1010
constructor(message) {
@@ -35,9 +35,6 @@ export class DataStoreUnavailableError extends Error {
3535
*
3636
* This class uses a singleton pattern.
3737
* Use DataStore.getDataStore() to get the singleton instance.
38-
*
39-
* When running locally, the data store is unavailable unless
40-
* required environment variables are set.
4138
*/
4239
export class DataStore {
4340
_tableName = ''
@@ -100,13 +97,8 @@ export class DataStore {
10097
* @returns true if the data store is available, false otherwise
10198
*/
10299
isDataStoreAvailable() {
103-
return (
104-
isRemote() ||
105-
Boolean(
106-
process.env.AWS_REGION &&
107-
process.env.MOBIFY_PROPERTY_ID &&
108-
process.env.DEPLOY_TARGET
109-
)
100+
return Boolean(
101+
process.env.AWS_REGION && process.env.MOBIFY_PROPERTY_ID && process.env.DEPLOY_TARGET
110102
)
111103
}
112104

packages/pwa-kit-runtime/src/utils/ssr-server/data-store.test.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from './data-store'
1414

1515
jest.mock('./utils', () => ({
16-
isRemote: jest.fn(),
1716
logMRTError: jest.fn()
1817
}))
1918

@@ -28,7 +27,7 @@ jest.mock('@aws-sdk/lib-dynamodb', () => ({
2827
GetCommand: jest.fn()
2928
}))
3029

31-
import {isRemote, logMRTError} from './utils'
30+
import {logMRTError} from './utils'
3231
import {DynamoDBClient} from '@aws-sdk/client-dynamodb'
3332
import {DynamoDBDocumentClient, GetCommand} from '@aws-sdk/lib-dynamodb'
3433

@@ -47,8 +46,7 @@ describe('DataStore', () => {
4746
send: mockSend
4847
})
4948

50-
// Default to remote environment
51-
isRemote.mockReturnValue(false)
49+
// Default to the data store being available
5250
process.env.AWS_REGION = 'ca-central-1'
5351
process.env.MOBIFY_PROPERTY_ID = 'my-project'
5452
process.env.DEPLOY_TARGET = 'my-target'
@@ -75,28 +73,14 @@ describe('DataStore', () => {
7573
})
7674

7775
describe('isDataStoreAvailable', () => {
78-
test('should return true when remote', () => {
79-
delete process.env.AWS_REGION
80-
delete process.env.MOBIFY_PROPERTY_ID
81-
delete process.env.DEPLOY_TARGET
82-
83-
const store = DataStore.getDataStore()
84-
85-
expect(store.isDataStoreAvailable()).toBe(true)
86-
})
87-
88-
test('should return true when local and all required env vars are set', () => {
89-
isRemote.mockReturnValue(true)
90-
76+
test('should return true when all required env vars are set', () => {
9177
const store = DataStore.getDataStore()
92-
9378
expect(store.isDataStoreAvailable()).toBe(true)
9479
})
9580

9681
test.each(['AWS_REGION', 'MOBIFY_PROPERTY_ID', 'DEPLOY_TARGET'])(
97-
'should return false when local and %s is missing',
82+
'should return false when %s is missing',
9883
(environmentVariableName) => {
99-
isRemote.mockReturnValue(true)
10084
delete process.env[environmentVariableName]
10185

10286
const store = DataStore.getDataStore()
@@ -108,9 +92,8 @@ describe('DataStore', () => {
10892

10993
describe('getEntry', () => {
11094
test.each(['AWS_REGION', 'MOBIFY_PROPERTY_ID', 'DEPLOY_TARGET'])(
111-
'should throw DataStoreUnavailableError when local and %s is missing',
95+
'should throw DataStoreUnavailableError when %s is missing',
11296
async (environmentVariableName) => {
113-
isRemote.mockReturnValue(true)
11497
delete process.env[environmentVariableName]
11598

11699
const store = DataStore.getDataStore()

0 commit comments

Comments
 (0)