Skip to content

Commit 986d018

Browse files
committed
update tests
1 parent af940d5 commit 986d018

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

packages/app/src/cli/services/app-logs/dev/poll-app-logs.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import camelcaseKeys from 'camelcase-keys'
1010

1111
const JWT_TOKEN = 'jwtToken'
1212
const API_KEY = 'apiKey'
13+
const TEST_LOGS_DIR = '/test/logs/dir'
1314

1415
vi.mock('./write-app-logs.js')
1516
vi.mock('@shopify/cli-kit/node/http')
@@ -245,11 +246,11 @@ describe('pollAppLogs', () => {
245246
await pollAppLogs({
246247
stdout,
247248
appLogsFetchInput: {jwtToken: JWT_TOKEN},
248-
apiKey: API_KEY,
249249
developerPlatformClient,
250250
resubscribeCallback: MOCKED_RESUBSCRIBE_CALLBACK,
251251
storeName: 'storeName',
252252
organizationId: 'organizationId',
253+
logsDir: TEST_LOGS_DIR,
253254
})
254255
await vi.advanceTimersToNextTimerAsync()
255256

@@ -259,9 +260,9 @@ describe('pollAppLogs', () => {
259260
expect(writeAppLogsToFile).toHaveBeenCalledWith({
260261
appLog: RESPONSE_DATA.app_logs[0],
261262
appLogPayload: appLogPayloadZero,
262-
apiKey: API_KEY,
263263
stdout,
264264
storeName: 'storeName',
265+
logsDir: TEST_LOGS_DIR,
265266
})
266267

267268
const appLogPayloadOne = new FunctionRunLog(
@@ -270,16 +271,16 @@ describe('pollAppLogs', () => {
270271
expect(writeAppLogsToFile).toHaveBeenCalledWith({
271272
appLog: RESPONSE_DATA.app_logs[1],
272273
appLogPayload: appLogPayloadOne,
273-
apiKey: API_KEY,
274274
stdout,
275275
storeName: 'storeName',
276+
logsDir: TEST_LOGS_DIR,
276277
})
277278
expect(writeAppLogsToFile).toHaveBeenCalledWith({
278279
appLog: RESPONSE_DATA.app_logs[2],
279280
appLogPayload: JSON.parse(RESPONSE_DATA.app_logs[2]!.payload),
280-
apiKey: API_KEY,
281281
stdout,
282282
storeName: 'storeName',
283+
logsDir: TEST_LOGS_DIR,
283284
})
284285

285286
expect(components.useConcurrentOutputContext).toHaveBeenCalledWith(
@@ -350,11 +351,11 @@ describe('pollAppLogs', () => {
350351
await pollAppLogs({
351352
stdout,
352353
appLogsFetchInput: {jwtToken: JWT_TOKEN},
353-
apiKey: API_KEY,
354354
developerPlatformClient: mockedDeveloperPlatformClient,
355355
resubscribeCallback: MOCKED_RESUBSCRIBE_CALLBACK,
356356
storeName: 'storeName',
357357
organizationId: 'organizationId',
358+
logsDir: TEST_LOGS_DIR,
358359
})
359360

360361
expect(MOCKED_RESUBSCRIBE_CALLBACK).toHaveBeenCalled()
@@ -372,11 +373,11 @@ describe('pollAppLogs', () => {
372373
await pollAppLogs({
373374
stdout,
374375
appLogsFetchInput: {jwtToken: JWT_TOKEN},
375-
apiKey: API_KEY,
376376
developerPlatformClient: mockedDeveloperPlatformClient,
377377
resubscribeCallback: MOCKED_RESUBSCRIBE_CALLBACK,
378378
storeName: 'storeName',
379379
organizationId: 'organizationId',
380+
logsDir: TEST_LOGS_DIR,
380381
})
381382

382383
expect(outputWarnSpy).toHaveBeenCalledWith('Request throttled while polling app logs.', stdout)
@@ -398,11 +399,11 @@ describe('pollAppLogs', () => {
398399
await pollAppLogs({
399400
stdout,
400401
appLogsFetchInput: {jwtToken: JWT_TOKEN},
401-
apiKey: API_KEY,
402402
developerPlatformClient: mockedDeveloperPlatformClient,
403403
resubscribeCallback: MOCKED_RESUBSCRIBE_CALLBACK,
404404
storeName: 'storeName',
405405
organizationId: 'organizationId',
406+
logsDir: TEST_LOGS_DIR,
406407
})
407408

408409
// Then
@@ -441,11 +442,11 @@ describe('pollAppLogs', () => {
441442
await pollAppLogs({
442443
stdout,
443444
appLogsFetchInput: {jwtToken: JWT_TOKEN},
444-
apiKey: API_KEY,
445445
developerPlatformClient: mockedDeveloperPlatformClient,
446446
resubscribeCallback: MOCKED_RESUBSCRIBE_CALLBACK,
447447
storeName: 'storeName',
448448
organizationId: 'organizationId',
449+
logsDir: TEST_LOGS_DIR,
449450
})
450451

451452
// When/Then

packages/app/src/cli/services/app-logs/dev/write-app-logs.test.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {writeAppLogsToFile} from './write-app-logs.js'
22
import {AppLogData, AppLogPayload, FunctionRunLog} from '../types.js'
33
import {joinPath} from '@shopify/cli-kit/node/path'
4-
import {writeLog} from '@shopify/cli-kit/node/logs'
4+
import {writeFile} from '@shopify/cli-kit/node/fs'
55
import {describe, expect, test, vi, beforeEach} from 'vitest'
66
import camelcaseKeys from 'camelcase-keys'
77
import {formatLocalDate} from '@shopify/cli-kit/common/string'
88

9-
vi.mock('@shopify/cli-kit/node/logs')
9+
vi.mock('@shopify/cli-kit/node/fs')
1010

1111
const APP_LOG: AppLogData = {
1212
shop_id: 1,
@@ -33,8 +33,8 @@ const NEW_APP_LOG: AppLogData = {
3333
}
3434

3535
const FUNCTION_RUN_PAYLOAD = new FunctionRunLog(camelcaseKeys(JSON.parse(APP_LOG.payload)))
36-
const API_KEY = 'apiKey'
3736
const STORE_NAME = 'storeName'
37+
const TEST_LOGS_DIR = '/test/logs/dir'
3838

3939
describe('writeAppLogsToFile', () => {
4040
let stdout: any
@@ -45,17 +45,16 @@ describe('writeAppLogsToFile', () => {
4545

4646
test('calls writeLog with the FunctionRunLog payload type', async () => {
4747
// Given
48-
// determine the fileName and path
48+
// determine the fileName
4949
const fileName = `20240522_150641_827Z_${APP_LOG.source_namespace}_${APP_LOG.source}`
50-
const path = joinPath(API_KEY, fileName)
5150

5251
// When
5352
const returnedPath = await writeAppLogsToFile({
5453
appLog: APP_LOG,
5554
appLogPayload: FUNCTION_RUN_PAYLOAD,
56-
apiKey: API_KEY,
5755
stdout,
5856
storeName: STORE_NAME,
57+
logsDir: TEST_LOGS_DIR,
5958
})
6059

6160
// Then
@@ -75,29 +74,29 @@ describe('writeAppLogsToFile', () => {
7574
}
7675
const expectedLogData = JSON.stringify(expectedSaveData, null, 2)
7776

78-
expect(returnedPath.fullOutputPath.startsWith(path)).toBe(true)
79-
expect(writeLog).toHaveBeenCalledWith(expect.stringContaining(path), expectedLogData)
77+
expect(writeFile).toHaveBeenCalledWith(expect.stringContaining(fileName), expectedLogData)
78+
expect(returnedPath.fullOutputPath).toEqual(expect.stringContaining(joinPath(TEST_LOGS_DIR, fileName)))
79+
expect(returnedPath.fullOutputPath).toEqual(expect.stringContaining(TEST_LOGS_DIR))
8080
})
8181

8282
test('calls writeLog with strings when no matching payload type', async () => {
8383
// Given
84-
// determine the fileName and path
85-
const fileName = `20240522_150641_827Z_${APP_LOG.source_namespace}_${APP_LOG.source}`
86-
const path = joinPath(API_KEY, fileName)
84+
// determine the fileName
85+
const fileName = `20240522_150641_827Z_${NEW_APP_LOG.source_namespace}_${NEW_APP_LOG.source}`
8786

8887
// When
8988
const returnedPath = await writeAppLogsToFile({
9089
appLog: NEW_APP_LOG,
9190
appLogPayload: JSON.parse(NEW_APP_LOG.payload),
92-
apiKey: API_KEY,
9391
stdout,
9492
storeName: STORE_NAME,
93+
logsDir: TEST_LOGS_DIR,
9594
})
9695

9796
// Then
98-
expect(returnedPath.fullOutputPath.startsWith(path)).toBe(true)
99-
expect(writeLog).toHaveBeenCalledWith(
100-
expect.stringContaining(path),
97+
expect(returnedPath.fullOutputPath).toEqual(expect.stringContaining(joinPath(TEST_LOGS_DIR, fileName)))
98+
expect(writeFile).toHaveBeenCalledWith(
99+
expect.stringContaining(fileName),
101100
expectedLogDataFromAppEvent(NEW_APP_LOG, JSON.parse(NEW_APP_LOG.payload)),
102101
)
103102
})

packages/app/src/cli/services/dev/processes/app-logs-polling.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import {DeveloperPlatformClient} from '../../../utilities/developer-platform-cli
99
import * as appLogsUtils from '../../app-logs/utils.js'
1010
import {AppEventWatcher} from '../app-events/app-event-watcher.js'
1111
import {AbortSignal} from '@shopify/cli-kit/node/abort'
12-
import {createLogsDir} from '@shopify/cli-kit/node/logs'
12+
import {mkdir} from '@shopify/cli-kit/node/fs'
1313
import {outputDebug} from '@shopify/cli-kit/node/output'
1414
import {describe, expect, vi, Mock, beforeEach, test} from 'vitest'
1515

16-
vi.mock('@shopify/cli-kit/node/logs')
16+
vi.mock('@shopify/cli-kit/node/fs')
1717
vi.mock('@shopify/cli-kit/node/output')
1818
vi.mock('../../app-logs/dev/poll-app-logs.js')
1919

@@ -102,7 +102,7 @@ describe('app-logs-polling', () => {
102102

103103
developerPlatformClient = testDeveloperPlatformClient({subscribeToAppLogs})
104104

105-
vi.mocked(createLogsDir).mockResolvedValue()
105+
vi.mocked(mkdir).mockResolvedValue()
106106
vi.mocked(pollAppLogs).mockResolvedValue()
107107
vi.spyOn(appLogsUtils, 'subscribeToAppLogs').mockResolvedValue(JWT_TOKEN)
108108
})
@@ -144,12 +144,12 @@ describe('app-logs-polling', () => {
144144
'organizationId',
145145
stdout,
146146
)
147-
expect(createLogsDir).toHaveBeenCalledWith(API_KEY)
147+
expect(mkdir).toHaveBeenCalledWith(localApp.getLogsDir())
148148
expect(pollAppLogs).toHaveBeenCalledOnce()
149149
expect(vi.mocked(pollAppLogs).mock.calls[0]?.[0]).toMatchObject({
150150
stdout,
151151
appLogsFetchInput: {jwtToken: JWT_TOKEN},
152-
apiKey: API_KEY,
152+
logsDir: localApp.getLogsDir(),
153153
})
154154

155155
const eventCallback = appWatcher.onEvent.mock.calls[0][0]

0 commit comments

Comments
 (0)