Skip to content

Commit

Permalink
Merge branch 'release-2.7.0' of https://github.com/Sunbird-Ed/sunbird…
Browse files Browse the repository at this point in the history
…-mobile-sdk into release-2.7.0
  • Loading branch information
balakrishna-m committed Jan 3, 2020
2 parents a8aa994 + 43fef90 commit 66def08
Show file tree
Hide file tree
Showing 17 changed files with 348 additions and 96 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
"author": "",
"license": "ISC",
"dependencies": {
"@project-sunbird/client-services": "git+https://github.com/Sunbird-Ed/sunbird-client-services.git",
"crypto-js": "^3.1.9-1",
"dayjs": "^1.8.17",
"inversify": "^5.0.1",
"jsonwebtoken": "^8.4.0",
"pako": "^1.0.8",
"qs": "^6.6.0",
"reflect-metadata": "^0.1.13",
"sunbird-client-data-models": "git+https://github.com/arfath-gwl/sunbird-client-data-models#v1.0.4",
"typescript-collections": "^1.3.2",
"uuid": "^3.3.2",
"whatwg-fetch": "^3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions src/content/def/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Content as ContentData} from 'sunbird-client-data-models';
export {Content as ContentData, LicenseDetails, AltMsg as ComingSoonMsg, OriginData} from 'sunbird-client-data-models';
import {Content as ContentData} from '@project-sunbird/client-services';
export {Content as ContentData, LicenseDetails, AltMsg as ComingSoonMsg, OriginData} from '@project-sunbird/client-services';

import {Rollup} from '../../telemetry';
import {ContentAccess} from '../../profile';
Expand Down
101 changes: 52 additions & 49 deletions src/content/handlers/get-child-contents-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import {ChildContentsHandler} from './get-child-contents-handler';
import {DbService} from '../../db';
import {GetContentDetailsHandler} from './get-content-details-handler';
import {ContentEntry} from '../db/schema';
import {ContentMapper} from '../util/content-mapper';
import {of} from 'rxjs';
import {ChildContent, HierarchyInfo} from '..';
import { ChildContentsHandler } from './get-child-contents-handler';
import { DbService } from '../../db';
import { GetContentDetailsHandler } from './get-content-details-handler';
import { ContentEntry } from '../db/schema';
import { ContentMapper } from '../util/content-mapper';
import { of } from 'rxjs';
import { ChildContent, HierarchyInfo } from '..';
import { FileService } from '../../util/file/def/file-service';

describe('ChildContentsHandler', () => {
let childContentHandler: ChildContentsHandler;
const mockDbService: Partial<DbService> = {};
const mockGetContentDetailsHandler: Partial<GetContentDetailsHandler> = {};
const mockFileService: Partial<FileService> = {};

beforeAll(() => {
childContentHandler = new ChildContentsHandler(
mockDbService as DbService,
mockGetContentDetailsHandler as GetContentDetailsHandler
mockGetContentDetailsHandler as GetContentDetailsHandler,
mockFileService as FileService
);
});

Expand Down Expand Up @@ -47,7 +50,7 @@ describe('ChildContentsHandler', () => {
};
const childContentsMap = new Map();
childContentsMap.set('IDENTIFIER', 'd0_id');
ContentMapper.mapContentDBEntryToContent = jest.fn(() => of([]));
ContentMapper.mapContentDBEntryToContent = jest.fn(() => ({hierarchyInfo: {data: ''}}));
const data = JSON.parse(request[ContentEntry.COLUMN_NAME_LOCAL_DATA]);
mockDbService.execute = jest.fn(() => of([]));
// act
Expand All @@ -60,34 +63,6 @@ describe('ChildContentsHandler', () => {
});
});

// it('should not be fetch content', async(done) => {
// // arrange
// const request: ContentEntry.SchemaMap = {
// identifier: 'IDENTIFIER',
// server_data: 'SERVER_DATA',
// local_data: '{"children": [{"ALL": 0}, "do_234", "do_345"]}',
// mime_type: 'MIME_TYPE',
// manifest_version: 'MAINFEST_VERSION',
// content_type: 'CONTENT_TYPE'
// };
// const currentLevel = -1;
// const level = 2;
// ContentMapper.mapContentDBEntryToContent = jest.fn(() => of([]));
// mockDbService.execute = jest.fn(() => of([]));
// const data = JSON.parse(request[ContentEntry.COLUMN_NAME_LOCAL_DATA]);
// console.log(data.children[0].ALL);
// // JSON.parse = jest.fn().mockImplementationOnce(() => {
// // return request[ContentEntry.COLUMN_NAME_LOCAL_DATA];
// // });
// // act
// await childContentHandler.fetchChildrenOfContent(request, currentLevel, level).then(() => {
// // expect(JSON.parse(request[ContentEntry.COLUMN_NAME_LOCAL_DATA])).toHaveBeenCalled();
// expect(data.children[0].ALL).toEqual(0);
// done();
// });
// // assert
// });

it('should parent child relation', (done) => {
// arrange
const request: ContentEntry.SchemaMap = {
Expand All @@ -114,10 +89,10 @@ describe('ChildContentsHandler', () => {
identifier: 'SAMPLE_IDENTIFIER_1',
contentType: 'SAMPLE_CONTENT_TYPE_1'
},
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
const identifier = 'IDENTIFIER';
mockGetContentDetailsHandler.fetchFromDB = jest.fn(() => of([]));
// act
Expand All @@ -133,10 +108,10 @@ describe('ChildContentsHandler', () => {
identifier: 'SAMPLE_IDENTIFIER_1',
contentType: 'SAMPLE_CONTENT_TYPE_1'
},
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
const currentIdentifier = 'SAMPLE_CURRENT_IDENTIFIER';
const contentKeyList = ['SAMPLE_IDENTIFIER_1', 'SAMPLE_IDENTIFIER_2',
'SAMPLE_IDENTIFIER_1/SAMPLE_IDENTIFIER_2/SAMPLE_CURRENT_IDENTIFIER'];
Expand All @@ -152,10 +127,10 @@ describe('ChildContentsHandler', () => {
identifier: 'SAMPLE_IDENTIFIER_1',
contentType: 'SAMPLE_CONTENT_TYPE_1'
},
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
{
identifier: 'SAMPLE_IDENTIFIER_2',
contentType: 'SAMPLE_CONTENT_TYPE_2'
}];
const currentIdentifier = 'SAMPLE_CURRENT_IDENTIFIER';
const contentKeyList = ['SAMPLE_IDENTIFIER_1', 'SAMPLE_IDENTIFIER_2',
'SAMPLE_IDENTIFIER_1/SAMPLE_IDENTIFIER_2/SAMPLE_CURRENT_IDENTIFIER'];
Expand All @@ -164,4 +139,32 @@ describe('ChildContentsHandler', () => {
// assert
done();
});

it('should get ChildIdentifiers From Manifest', (done) => {
// arrange
mockFileService.readAsText = jest.fn(() => {
});
const readAsText = (mockFileService.readAsText as jest.Mock)
.mockResolvedValue(JSON.stringify({ archive: { items: [{ identifier: 'pass' }, { identifier: 'pass-2' }] } }));
readAsText().then((value) => {
return value;
});
// act
childContentHandler.getChildIdentifiersFromManifest('textbook_unit_1').then(() => {
// assert
expect(mockFileService.readAsText).toHaveBeenCalledWith('file:///textbook_unit_1', 'manifest.json');
done();
});
});

it('should get ChildIdentifiers From Manifest for catch part', async(done) => {
// arrange
mockFileService.readAsText = jest.fn(() => Promise.reject('textbook'));
// act
childContentHandler.getChildIdentifiersFromManifest('textbook_unit_1').then(() => {
// assert
expect(mockFileService.readAsText).toHaveBeenCalledWith('file:///textbook_unit_1', 'manifest.json');
done();
});
});
});
47 changes: 47 additions & 0 deletions src/content/handlers/get-content-heirarchy-handler.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { GetContentHeirarchyHandler } from './get-content-heirarchy-handler';
import { ApiService } from '../..';
import { ContentServiceConfig, ContentDetailRequest } from '..';
import { of } from 'rxjs';

describe('GetContentHeirarchyHandler', () => {
let getContentHeirarchyHandler: GetContentHeirarchyHandler;
const mockApiService: Partial<ApiService> = {};
const mockContentServiceConfig: Partial<ContentServiceConfig> = {};

beforeAll(() => {
getContentHeirarchyHandler = new GetContentHeirarchyHandler(
mockApiService as ApiService,
mockContentServiceConfig as ContentServiceConfig
);
});

beforeEach(() => {
jest.clearAllMocks();
});

it('should be create a instance of getContentHeirarchyHandler', () => {
expect(getContentHeirarchyHandler).toBeTruthy();
});

it('shpuld handle mapContentFromContentHeirarchyData by invoked handle()', (done) => {
// arrange
const request: ContentDetailRequest = {
contentId: 'do_123'
};
mockApiService.fetch = jest.fn(() => of({
body: {
result: {
content: {
children: ['child-1', 'child-2']
}
}
}
}));
// act
getContentHeirarchyHandler.handle(request).subscribe(() => {
expect(mockApiService.fetch).toHaveBeenCalled();
done();
});
// assert
});
});
31 changes: 17 additions & 14 deletions src/content/impl/content-service-impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('ContentServiceImpl', () => {
};

beforeAll(() => {
container.bind<ContentService>(InjectionTokens.CONTENT_SERVICE).to(ContentServiceImpl);
container.bind<ContentService>(InjectionTokens.CONTENT_SERVICE).to(ContentServiceImpl).inTransientScope();
container.bind<SdkConfig>(InjectionTokens.SDK_CONFIG).toConstantValue(mockSdkConfig as SdkConfig);
container.bind<ApiService>(InjectionTokens.API_SERVICE).toConstantValue(mockApiService as ApiService);
container.bind<DbService>(InjectionTokens.DB_SERVICE).toConstantValue(mockDbService as DbService);
Expand Down Expand Up @@ -553,6 +553,12 @@ describe('ContentServiceImpl', () => {
});
it('should be find child content', (done) => {
// arrange
(ChildContentsHandler as any as jest.Mock<ChildContentsHandler>).mockImplementation(() => {
return {
fetchChildrenOfContent: jest.fn(() => Promise.resolve({}))
};
});
contentService = container.get(InjectionTokens.CONTENT_SERVICE);
const hierarInfoData: HierarchyInfo[] = [{
identifier: 'd0_123',
contentType: 'content_type'
Expand All @@ -567,19 +573,15 @@ describe('ContentServiceImpl', () => {
JSON.parse = jest.fn().mockImplementationOnce(() => {
return mockDbService.read;
});
(ChildContentsHandler as any as jest.Mock<ChildContentsHandler>).mockImplementation(() => {
return {
fetchChildrenOfContent: jest.fn(() => Promise.resolve({}))
};
});

ArrayUtil.joinPreservingQuotes = jest.fn(() => of([]));
mockDbService.execute = jest.fn(() => of([]));
// act
contentService.getChildContents(request).subscribe(() => {
// assert
expect(mockDbService.read).toHaveBeenCalled();
expect(ArrayUtil.joinPreservingQuotes).toHaveBeenCalled();
expect(mockDbService.execute).toBeCalled();
// expect(ArrayUtil.joinPreservingQuotes).toHaveBeenCalled();
// expect(mockDbService.execute).toBeCalled();
done();
});
// assert
Expand Down Expand Up @@ -611,16 +613,17 @@ describe('ContentServiceImpl', () => {
});
it('should used for search content', (done) => {
// arrange
const request: ContentSearchCriteria = {
limit: 1,
offset: 2
};
(SearchContentHandler as any as jest.Mock<SearchContentHandler>).mockImplementation(() => {
return {
getSearchContentRequest: jest.fn(() => of('')),
mapSearchResponse: jest.fn(() => of(''))
getSearchContentRequest: jest.fn(() => ({filter: {}})),
mapSearchResponse: jest.fn(() => ({id: 'sid'}))
};
});
const request: ContentSearchCriteria = {
limit: 1,
offset: 2
};
contentService = container.get(InjectionTokens.CONTENT_SERVICE);

mockSharedPreferences.getString = jest.fn(() => of([]));
spyOn(mockApiService, 'fetch').and.returnValue(of({
Expand Down
2 changes: 1 addition & 1 deletion src/course/def/batch.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Batch} from 'sunbird-client-data-models';
export {Batch} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/course/def/course.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Course, CourseCertificate} from 'sunbird-client-data-models';
export {Course, CourseCertificate} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/faq/def/faq.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Faq, Faqs} from 'sunbird-client-data-models';
export {Faq, Faqs} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/framework/def/channel.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Channel} from 'sunbird-client-data-models';
export {Channel} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/framework/def/framework-category-code.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {FrameworkCategoryCode, FrameworkCategoryCodesGroup} from 'sunbird-client-data-models';
export {FrameworkCategoryCode, FrameworkCategoryCodesGroup} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/framework/def/framework.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {Framework, FrameworkCategory, CategoryTerm, CategoryAssociation} from 'sunbird-client-data-models';
export {Framework, FrameworkCategory, CategoryTerm, CategoryAssociation} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/page/def/page-assemble.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {PageAssemble, PageSections} from 'sunbird-client-data-models';
export {PageAssemble, PageSections} from '@project-sunbird/client-services';
2 changes: 1 addition & 1 deletion src/profile/def/server-profile.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {User as ServerProfile, RootOrg} from 'sunbird-client-data-models';
export {User as ServerProfile, RootOrg} from '@project-sunbird/client-services';
Loading

0 comments on commit 66def08

Please sign in to comment.