Skip to content

Commit d371fb0

Browse files
committed
tests passing, env mocking
1 parent 6ccfa8e commit d371fb0

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/deploy-web.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const deployWeb = async (config, log) => {
3636

3737
const remoteStorage = new RemoteStorage(bearerToken)
3838

39+
console.log('config.s3.folder is', config.s3.folder)
3940
const _log = log ? (f) => log(`deploying ${path.relative(dist, f)}`) : null
4041
await remoteStorage.uploadDir(dist, config.s3.folder, config, _log)
4142

test/lib/remote-storage.test.js

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('RemoteStorage', () => {
264264
expect(body.file.content).toBeDefined() // base64 encoded content
265265
})
266266

267-
test('should call PUT /files with slash-prefix', async () => {
267+
test('should call PUT /files without slash-prefix', async () => {
268268
global.addFakeFiles(vol, 'fakeDir', { 'index.js': 'fake content' })
269269
global.fetch.mockResolvedValue(mockResponse({ success: true }))
270270
const rs = new RemoteStorage(global.fakeAuthToken)
@@ -274,7 +274,7 @@ describe('RemoteStorage', () => {
274274

275275
const callArgs = global.fetch.mock.calls[0]
276276
const body = JSON.parse(callArgs[1].body)
277-
expect(body.file.name).toBe('/slash-prefix/index.js')
277+
expect(body.file.name).toBe('slash-prefix/index.js')
278278
})
279279

280280
test('should handle unknown Content-Type', async () => {
@@ -747,3 +747,57 @@ describe('RemoteStorage', () => {
747747
})
748748
})
749749
})
750+
751+
describe('RemoteStorage environment URL selection', () => {
752+
// The deploymentServiceUrl is computed at module load time, so we need to
753+
// reset modules and set up mocks BEFORE requiring remote-storage
754+
755+
beforeEach(() => {
756+
jest.resetModules()
757+
global.fetch.mockReset()
758+
})
759+
760+
test('uses stage url when in stage environment', async () => {
761+
// Set up mock BEFORE requiring the module
762+
jest.doMock('@adobe/aio-lib-env', () => ({
763+
getCliEnv: jest.fn(() => 'stage'),
764+
PROD_ENV: 'prod',
765+
STAGE_ENV: 'stage'
766+
}))
767+
768+
// Now require the module fresh with the mock in place
769+
const RemoteStorageFresh = require('../../lib/remote-storage')
770+
771+
global.fetch.mockResolvedValue(mockResponse([]))
772+
const rs = new RemoteStorageFresh(global.fakeAuthToken)
773+
774+
await rs.folderExists('fakeprefix', createAppConfig())
775+
776+
expect(global.fetch).toHaveBeenCalledWith(
777+
expect.stringContaining('https://deploy-service.stg.app-builder.corp.adp.adobe.io'),
778+
expect.any(Object)
779+
)
780+
})
781+
782+
test('uses prod url when in prod environment', async () => {
783+
// Set up mock for prod environment
784+
jest.doMock('@adobe/aio-lib-env', () => ({
785+
getCliEnv: jest.fn(() => 'prod'),
786+
PROD_ENV: 'prod',
787+
STAGE_ENV: 'stage'
788+
}))
789+
790+
// Now require the module fresh with the mock in place
791+
const RemoteStorageFresh = require('../../lib/remote-storage')
792+
793+
global.fetch.mockResolvedValue(mockResponse([]))
794+
const rs = new RemoteStorageFresh(global.fakeAuthToken)
795+
796+
await rs.folderExists('fakeprefix', createAppConfig())
797+
798+
expect(global.fetch).toHaveBeenCalledWith(
799+
expect.stringContaining('https://deploy-service.app-builder.adp.adobe.io'),
800+
expect.any(Object)
801+
)
802+
})
803+
})

0 commit comments

Comments
 (0)