Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fileignoreconfig:
- filename: test/unit/commands/rollback.test.ts
checksum: d1f931f2d9a397131409399ad6463653e28b5a2224e870b641d9ba57c4418f18
- filename: package-lock.json
checksum: d24dfc90fb69ded83dfe4f6839cd17801e65a1f84be04244fb917e6bef6b5cc6
checksum: e8262e57f73252240a076fa99be712c4d1403c058378cc2bb23f897bb4e45648
version: "1.0"
1,398 changes: 716 additions & 682 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-launch",
"version": "1.10.0",
"version": "1.10.1",
"description": "Launch related operations",
"author": "Contentstack CLI",
"bin": {
Expand Down
143 changes: 126 additions & 17 deletions src/adapters/file-upload.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe('FileUpload Adapter', () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./dist');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm start');
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');

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

await fileUploadInstance.prepareAndUploadNewProjectFile();

expect(cliux.inquire).toHaveBeenCalledWith({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
});
expect(cliux.inquire).toHaveBeenCalledWith(
expect.objectContaining({
type: 'search-list',
name: 'responseMode',
message: 'Response mode',
choices: [
{ name: 'Buffered', value: 'buffered' },
{ name: 'Streaming', value: 'streaming' },
],
}),
);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);

createSignedUploadUrlMock.mockRestore();
Expand Down Expand Up @@ -386,7 +391,7 @@ describe('FileUpload Adapter', () => {
await fileUploadInstance.prepareAndUploadNewProjectFile();

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

const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'enableStreamingResponse',
(call) => call[0]?.name === 'responseMode',
);
expect(enableStreamingCalls.length).toBe(0);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);
Expand All @@ -444,7 +449,7 @@ describe('FileUpload Adapter', () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
(cliux.inquire as jest.Mock).mockResolvedValueOnce(true);
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
Expand Down Expand Up @@ -479,12 +484,17 @@ describe('FileUpload Adapter', () => {
(call) => call[0]?.name === 'serverCommand',
);
expect(serverCommandCalls.length).toBe(0);
expect(cliux.inquire).toHaveBeenCalledWith({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
});
expect(cliux.inquire).toHaveBeenCalledWith(
expect.objectContaining({
type: 'search-list',
name: 'responseMode',
message: 'Response mode',
choices: [
{ name: 'Buffered', value: 'buffered' },
{ name: 'Streaming', value: 'streaming' },
],
}),
);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(true);

createSignedUploadUrlMock.mockRestore();
Expand Down Expand Up @@ -529,7 +539,7 @@ describe('FileUpload Adapter', () => {
await fileUploadInstance.prepareAndUploadNewProjectFile();

const enableStreamingCalls = (cliux.inquire as jest.Mock).mock.calls.filter(
(call) => call[0]?.name === 'enableStreamingResponse',
(call) => call[0]?.name === 'responseMode',
);
expect(enableStreamingCalls.length).toBe(0);
expect(fileUploadInstance.config.isStreamingEnabled).toBe(false);
Expand All @@ -539,6 +549,105 @@ describe('FileUpload Adapter', () => {
uploadFileMock.mockRestore();
handleEnvImportFlowMock.mockRestore();
});

it.each([
['streaming', true],
['buffered', false],
])('should map Response Mode selection "%s" to isStreamingEnabled %s', async (input, expected) => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
(cliux.inquire as jest.Mock).mockResolvedValueOnce(input);

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'response-mode': undefined,
},
framework: 'GATSBY',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { GATSBY: './public' },
},
log: logMock,
exit: exitMock,
} as any);

const handleEnvImportFlowMock = jest
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
.mockResolvedValue(undefined);

await fileUploadInstance.prepareAndUploadNewProjectFile();

expect(fileUploadInstance.config.isStreamingEnabled).toBe(expected);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
handleEnvImportFlowMock.mockRestore();
});

it('Response Mode prompt should offer buffered and streaming choices', async () => {
(cliux.inquire as jest.Mock).mockResolvedValueOnce('test-project');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('Default');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('npm run build');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('./public');
(cliux.inquire as jest.Mock).mockResolvedValueOnce('streaming');

const createSignedUploadUrlMock = jest
.spyOn(FileUpload.prototype as any, 'createSignedUploadUrl')
.mockResolvedValue({ uploadUid: 'test-upload-uid' });
const archiveMock = jest
.spyOn(FileUpload.prototype as any, 'archive')
.mockResolvedValue({ zipName: 'test.zip', zipPath: '/path/to/test.zip', projectName: 'test-project' });
const uploadFileMock = jest
.spyOn(FileUpload.prototype as any, 'uploadFile')
.mockResolvedValue(undefined);

const fileUploadInstance = new FileUpload({
config: {
flags: {
'response-mode': undefined,
},
framework: 'GATSBY',
supportedFrameworksForServerCommands: ['ANGULAR', 'OTHER', 'REMIX', 'NUXT'],
outputDirectories: { GATSBY: './public' },
},
log: logMock,
exit: exitMock,
} as any);

const handleEnvImportFlowMock = jest
.spyOn(fileUploadInstance, 'handleEnvImportFlow' as any)
.mockResolvedValue(undefined);

await fileUploadInstance.prepareAndUploadNewProjectFile();

const responseModeCall = (cliux.inquire as jest.Mock).mock.calls.find(
(call) => call[0]?.name === 'responseMode',
);

expect(responseModeCall[0].type).toBe('search-list');
expect(responseModeCall[0].choices).toEqual([
{ name: 'Buffered', value: 'buffered' },
{ name: 'Streaming', value: 'streaming' },
]);

createSignedUploadUrlMock.mockRestore();
archiveMock.mockRestore();
uploadFileMock.mockRestore();
handleEnvImportFlowMock.mockRestore();
});
});
});

16 changes: 10 additions & 6 deletions src/adapters/file-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,16 @@ export default class FileUpload extends BaseClass {
}
}
if (!responseMode) {
this.config.isStreamingEnabled = (await cliux.inquire({
type: 'confirm',
name: 'enableStreamingResponse',
message: 'Enable Streaming Responses',
default: false,
})) as boolean;
const selectedResponseMode = (await cliux.inquire({
type: 'search-list',
name: 'responseMode',
message: 'Response mode',
choices: [
{ name: 'Buffered', value: 'buffered' },
{ name: 'Streaming', value: 'streaming' },
],
})) as string;
this.config.isStreamingEnabled = selectedResponseMode === 'streaming';
} else {
this.config.isStreamingEnabled = responseMode === 'streaming';
}
Expand Down
Loading
Loading