Skip to content

Commit

Permalink
fix: made changes to cater updated video detail api response (#1126)
Browse files Browse the repository at this point in the history
Co-authored-by: Maham Akif <[email protected]>
  • Loading branch information
mahamakifdar19 and Maham Akif authored Jul 22, 2024
1 parent 7620f17 commit 7947a71
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/components/microlearning/data/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const formatDuration = (durationInSeconds) => {
return `${minutes}:${seconds}`;
};

export const formatSkills = (skills) => skills?.['list-item'].map(skill => ({
export const formatSkills = (skills) => skills?.map(skill => ({
name: skill?.name,
description: skill?.description,
category: skill?.category?.name,
Expand All @@ -20,7 +20,7 @@ export const formatSkills = (skills) => skills?.['list-item'].map(skill => ({
export const transformVideoData = (data) => ({
videoUrl: data?.json_metadata?.download_link,
courseTitle: data?.parent_content_metadata?.title,
videoSummary: data?.summary_transcripts?.['list-item'],
videoSummary: data?.summary_transcripts?.[0],
transcriptUrls: data?.json_metadata?.transcript_urls,
videoSkills: formatSkills(data?.skills),
videoDuration: formatDuration(data?.json_metadata?.duration),
Expand Down
58 changes: 27 additions & 31 deletions src/components/microlearning/data/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import { formatDuration, formatSkills, transformVideoData } from './utils';

describe('Microlearning utils tests', () => {
const mockSkills = {
'list-item': [
{
name: 'Skill 1',
description: 'Description 1',
category: { name: 'Category 1' },
subcategory: { name: 'Subcategory 1' },
},
{
name: 'Skill 2',
description: 'Description 2',
category: { name: 'Category 2' },
subcategory: { name: 'Subcategory 2' },
},
],
};
const mockSkills = [
{
name: 'Skill 1',
description: 'Description 1',
category: { name: 'Category 1' },
subcategory: { name: 'Subcategory 1' },
},
{
name: 'Skill 2',
description: 'Description 2',
category: { name: 'Category 2' },
subcategory: { name: 'Subcategory 2' },
},
];

const mockData = {
json_metadata: {
Expand All @@ -27,19 +25,17 @@ describe('Microlearning utils tests', () => {
parent_content_metadata: {
title: 'Course Title',
},
summary_transcripts: {
'list-item': ['Transcript 1', 'Transcript 2'],
},
skills: {
'list-item': [
{
name: 'Skill 1',
description: 'Description 1',
category: { name: 'Category 1' },
subcategory: { name: 'Subcategory 1' },
},
],
},
summary_transcripts: [
'Transcript 1', 'Transcript 2',
],
skills: [
{
name: 'Skill 1',
description: 'Description 1',
category: { name: 'Category 1' },
subcategory: { name: 'Subcategory 1' },
},
],
};

it('should format 60 seconds correctly', () => {
Expand All @@ -64,14 +60,14 @@ describe('Microlearning utils tests', () => {
});

it('should handle empty skills list', () => {
expect(formatSkills({ 'list-item': [] })).toEqual([]);
expect(formatSkills([])).toEqual([]);
});

it('should transform video data correctly', () => {
expect(transformVideoData(mockData)).toEqual({
videoUrl: 'http://example.com/video.mp4',
courseTitle: 'Course Title',
videoSummary: ['Transcript 1', 'Transcript 2'],
videoSummary: 'Transcript 1',
transcriptUrls: ['http://example.com/transcript1.vtt'],
videoSkills: [
{
Expand Down

0 comments on commit 7947a71

Please sign in to comment.