Skip to content

Commit d7d0f9a

Browse files
Merge pull request #170 from contentstack/staging
Send X-CS-CLI header and allow selection for Response mode via search-list
2 parents 8694df7 + 5778785 commit d7d0f9a

11 files changed

Lines changed: 1060 additions & 738 deletions

File tree

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fileignoreconfig:
99
- filename: test/unit/commands/rollback.test.ts
1010
checksum: d1f931f2d9a397131409399ad6463653e28b5a2224e870b641d9ba57c4418f18
1111
- filename: package-lock.json
12-
checksum: d24dfc90fb69ded83dfe4f6839cd17801e65a1f84be04244fb917e6bef6b5cc6
12+
checksum: e8262e57f73252240a076fa99be712c4d1403c058378cc2bb23f897bb4e45648
1313
version: "1.0"

package-lock.json

Lines changed: 716 additions & 682 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-launch",
3-
"version": "1.10.0",
3+
"version": "1.10.1",
44
"description": "Launch related operations",
55
"author": "Contentstack CLI",
66
"bin": {

src/adapters/file-upload.test.ts

Lines changed: 126 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ describe('FileUpload Adapter', () => {
312312
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
313313
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./dist');
314314
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm start');
315-
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);
315+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');
316316

317317
const createSignedUploadUrlMock = jest
318318
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
@@ -340,12 +340,17 @@ describe('FileUpload Adapter', () => {
340340

341341
await fileUploadInstance.prepareAndUploadNewProjectFile();
342342

343-
expect(cliux.inquire).toHaveBeenCalledWith({
344-
type: 'confirm',
345-
name: 'enableStreamingResponse',
346-
message: 'Enable Streaming Responses',
347-
default: false,
348-
});
343+
expect(cliux.inquire).toHaveBeenCalledWith(
344+
expect.objectContaining({
345+
type: 'search-list',
346+
name: 'responseMode',
347+
message: 'Response mode',
348+
choices: [
349+
{ name: 'Buffered', value: 'buffered' },
350+
{ name: 'Streaming', value: 'streaming' },
351+
],
352+
}),
353+
);
349354
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);
350355

351356
createSignedUploadUrlMock.mockRestore();
@@ -386,7 +391,7 @@ describe('FileUpload Adapter', () => {
386391
await fileUploadInstance.prepareAndUploadNewProjectFile();
387392

388393
const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
389-
(call) => call[0]?.name === 'enableStreamingResponse',
394+
(call) => call[0]?.name === 'responseMode',
390395
);
391396
expect(enableStreamingCalls.length).toBe(0);
392397
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);
@@ -429,7 +434,7 @@ describe('FileUpload Adapter', () => {
429434
await fileUploadInstance.prepareAndUploadNewProjectFile();
430435

431436
const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
432-
(call) => call[0]?.name === 'enableStreamingResponse',
437+
(call) => call[0]?.name === 'responseMode',
433438
);
434439
expect(enableStreamingCalls.length).toBe(0);
435440
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);
@@ -444,7 +449,7 @@ describe('FileUpload Adapter', () => {
444449
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
445450
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
446451
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
447-
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);
452+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');
448453

449454
const createSignedUploadUrlMock = jest
450455
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
@@ -479,12 +484,17 @@ describe('FileUpload Adapter', () => {
479484
(call) => call[0]?.name === 'serverCommand',
480485
);
481486
expect(serverCommandCalls.length).toBe(0);
482-
expect(cliux.inquire).toHaveBeenCalledWith({
483-
type: 'confirm',
484-
name: 'enableStreamingResponse',
485-
message: 'Enable Streaming Responses',
486-
default: false,
487-
});
487+
expect(cliux.inquire).toHaveBeenCalledWith(
488+
expect.objectContaining({
489+
type: 'search-list',
490+
name: 'responseMode',
491+
message: 'Response mode',
492+
choices: [
493+
{ name: 'Buffered', value: 'buffered' },
494+
{ name: 'Streaming', value: 'streaming' },
495+
],
496+
}),
497+
);
488498
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);
489499

490500
createSignedUploadUrlMock.mockRestore();
@@ -529,7 +539,7 @@ describe('FileUpload Adapter', () => {
529539
await fileUploadInstance.prepareAndUploadNewProjectFile();
530540

531541
const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
532-
(call) => call[0]?.name === 'enableStreamingResponse',
542+
(call) => call[0]?.name === 'responseMode',
533543
);
534544
expect(enableStreamingCalls.length).toBe(0);
535545
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);
@@ -539,6 +549,105 @@ describe('FileUpload Adapter', () => {
539549
uploadFileMock.mockRestore();
540550
handleEnvImportFlowMock.mockRestore();
541551
});
552+
553+
it.each([
554+
['streaming', true],
555+
['buffered', false],
556+
])('should map Response Mode selection "%s" to isStreamingEnabled %s', async (input, expected) => {
557+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
558+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
559+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
560+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
561+
(cliux.inquire as jest.Mock).mockResolvedValueOnce(input);
562+
563+
const createSignedUploadUrlMock = jest
564+
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
565+
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
566+
const archiveMock = jest
567+
.spyOn(FileUpload.prototype as any, 'archive')
568+
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
569+
const uploadFileMock = jest
570+
.spyOn(FileUpload.prototype as any, 'uploadFile')
571+
.mockResolvedValue(undefined);
572+
573+
const fileUploadInstance = new FileUpload({
574+
config: {
575+
flags: {
576+
'response-mode': undefined,
577+
},
578+
framework: 'GATSBY',
579+
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
580+
outputDirectories: { GATSBY: './public' },
581+
},
582+
log: logMock,
583+
exit: exitMock,
584+
} as any);
585+
586+
const handleEnvImportFlowMock = jest
587+
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
588+
.mockResolvedValue(undefined);
589+
590+
await fileUploadInstance.prepareAndUploadNewProjectFile();
591+
592+
expect(fileUploadInstance.config.isStreamingEnabled).toBe(expected);
593+
594+
createSignedUploadUrlMock.mockRestore();
595+
archiveMock.mockRestore();
596+
uploadFileMock.mockRestore();
597+
handleEnvImportFlowMock.mockRestore();
598+
});
599+
600+
it('Response Mode prompt should offer buffered and streaming choices', async () => {
601+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
602+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
603+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
604+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
605+
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');
606+
607+
const createSignedUploadUrlMock = jest
608+
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
609+
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
610+
const archiveMock = jest
611+
.spyOn(FileUpload.prototype as any, 'archive')
612+
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
613+
const uploadFileMock = jest
614+
.spyOn(FileUpload.prototype as any, 'uploadFile')
615+
.mockResolvedValue(undefined);
616+
617+
const fileUploadInstance = new FileUpload({
618+
config: {
619+
flags: {
620+
'response-mode': undefined,
621+
},
622+
framework: 'GATSBY',
623+
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
624+
outputDirectories: { GATSBY: './public' },
625+
},
626+
log: logMock,
627+
exit: exitMock,
628+
} as any);
629+
630+
const handleEnvImportFlowMock = jest
631+
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
632+
.mockResolvedValue(undefined);
633+
634+
await fileUploadInstance.prepareAndUploadNewProjectFile();
635+
636+
const responseModeCall = (cliux.inquire as jest.Mock).mock.calls.find(
637+
(call) => call[0]?.name === 'responseMode',
638+
);
639+
640+
expect(responseModeCall[0].type).toBe('search-list');
641+
expect(responseModeCall[0].choices).toEqual([
642+
{ name: 'Buffered', value: 'buffered' },
643+
{ name: 'Streaming', value: 'streaming' },
644+
]);
645+
646+
createSignedUploadUrlMock.mockRestore();
647+
archiveMock.mockRestore();
648+
uploadFileMock.mockRestore();
649+
handleEnvImportFlowMock.mockRestore();
650+
});
542651
});
543652
});
544653

src/adapters/file-upload.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,16 @@ export default class FileUpload extends BaseClass {
250250
}
251251
}
252252
if (!responseMode) {
253-
this.config.isStreamingEnabled = (await cliux.inquire({
254-
type: 'confirm',
255-
name: 'enableStreamingResponse',
256-
message: 'Enable Streaming Responses',
257-
default: false,
258-
})) as boolean;
253+
const selectedResponseMode = (await cliux.inquire({
254+
type: 'search-list',
255+
name: 'responseMode',
256+
message: 'Response mode',
257+
choices: [
258+
{ name: 'Buffered', value: 'buffered' },
259+
{ name: 'Streaming', value: 'streaming' },
260+
],
261+
})) as string;
262+
this.config.isStreamingEnabled = selectedResponseMode === 'streaming';
259263
} else {
260264
this.config.isStreamingEnabled = responseMode === 'streaming';
261265
}

0 commit comments

Comments
 (0)