Skip to content

Commit 548a209

Browse files
committed
Merge branch 'feature/RI-4186-Upload_custom_tutorials' into fe/feature/I-4181_to-tutorial-button
2 parents b836b67 + d7b7036 commit 548a209

File tree

5 files changed

+29
-4
lines changed

5 files changed

+29
-4
lines changed

redisinsight/api/src/__mocks__/custom-tutorial.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const mockCustomTutorialManifestProvider = jest.fn(() => ({
161161
getOriginalManifestJson: jest.fn().mockResolvedValue(mockCustomTutorialManifestJson),
162162
getManifestJson: jest.fn().mockResolvedValue(mockCustomTutorialManifestJson),
163163
generateTutorialManifest: jest.fn().mockResolvedValue(mockCustomTutorialManifest),
164+
isOriginalManifestExists: jest.fn().mockResolvedValue(true),
164165
}));
165166

166167
export const mockCustomTutorialRepository = jest.fn(() => ({

redisinsight/api/src/modules/custom-tutorial/custom-tutorial.service.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ describe('CustomTutorialService', () => {
108108

109109
it('Should create custom tutorial from external url (w/o manifest)', async () => {
110110
customTutorialManifestProvider.getOriginalManifestJson.mockResolvedValue(null);
111+
customTutorialManifestProvider.isOriginalManifestExists.mockResolvedValue(false);
111112

112113
const result = await service.create(mockUploadCustomTutorialExternalLinkDto);
113114

@@ -124,6 +125,18 @@ describe('CustomTutorialService', () => {
124125
}
125126
});
126127

128+
it('Should throw BadRequestException in case when manifest exists but unable to parse it', async () => {
129+
customTutorialManifestProvider.getOriginalManifestJson.mockResolvedValueOnce(null);
130+
customTutorialManifestProvider.isOriginalManifestExists.mockResolvedValueOnce(true);
131+
132+
try {
133+
await service.create(mockUploadCustomTutorialExternalLinkDto);
134+
} catch (e) {
135+
expect(e).toBeInstanceOf(BadRequestException);
136+
expect(e.message).toEqual('Unable to parse manifest.json file');
137+
}
138+
});
139+
127140
it('Should throw BadRequestException in case when manifest is not an object', async () => {
128141
customTutorialManifestProvider.getOriginalManifestJson.mockResolvedValue([mockCustomTutorialManifest]);
129142

redisinsight/api/src/modules/custom-tutorial/custom-tutorial.service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export class CustomTutorialService {
4141
private async validateManifestJson(path: string): Promise<void> {
4242
const manifest = await this.customTutorialManifestProvider.getOriginalManifestJson(path);
4343

44+
if (!manifest && await this.customTutorialManifestProvider.isOriginalManifestExists(path)) {
45+
throw new BadRequestException('Unable to parse manifest.json file');
46+
}
47+
4448
if (manifest) {
4549
if (!isPlainObject(manifest)) {
4650
throw new BadRequestException('Manifest json should be an object');

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@ describe('CustomTutorialManifestProvider', () => {
195195

196196
const result = await service.generateTutorialManifest(mockCustomTutorial);
197197

198-
expect(result).toEqual(null);
198+
expect(result).toEqual({
199+
...mockCustomTutorialManifest,
200+
children: [],
201+
});
199202
});
200203

201204
it('should return null in case of any error', async () => {

redisinsight/api/src/modules/custom-tutorial/providers/custom-tutorial.manifest.provider.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export class CustomTutorialManifestProvider {
8484
return manifest;
8585
}
8686

87+
public async isOriginalManifestExists(path: string): Promise<boolean> {
88+
return fs.existsSync(join(path, MANIFEST_FILE));
89+
}
90+
8791
public async getOriginalManifestJson(path: string): Promise<RootCustomTutorialManifest> {
8892
try {
8993
return JSON.parse(
@@ -143,16 +147,16 @@ export class CustomTutorialManifestProvider {
143147
*/
144148
public async generateTutorialManifest(tutorial: CustomTutorial): Promise<RootCustomTutorialManifest> {
145149
try {
146-
const manifest = await this.getManifestJson(tutorial.absolutePath);
150+
const manifest = await this.getManifestJson(tutorial.absolutePath) || {} as RootCustomTutorialManifest;
147151

148152
return {
149153
...manifest,
150154
_actions: tutorial.actions,
151155
_path: tutorial.path,
152156
type: CustomTutorialManifestType.Group,
153157
id: tutorial.id,
154-
label: tutorial.name || manifest.label,
155-
children: manifest.children || [],
158+
label: tutorial.name || manifest?.label,
159+
children: manifest?.children || [],
156160
};
157161
} catch (e) {
158162
this.logger.warn('Unable to generate manifest for tutorial', e);

0 commit comments

Comments
 (0)