Skip to content

Commit

Permalink
Merge pull request #26 from aashutoshbane/export-course-upload-progre…
Browse files Browse the repository at this point in the history
…ss-preview-link

Added endpoints for course upload progress, export course & course preview link
  • Loading branch information
ukmadlz authored Sep 25, 2019
2 parents d1b2e85 + 3abff0d commit 7c2b304
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
{
"name": "@packt/rustici-sdk",
"version": "1.2.0",
"version": "1.3.0",
"description": "Wrapper for Rustici API",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/course-upload-import-result-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ICourse from "./rustici-course-interface";

export default interface ICourseUploadImportResult {
webPathToCourse: string;
parserWarnings: string[];
courseLanguages: string[];
course: ICourse;
};
8 changes: 8 additions & 0 deletions src/interfaces/course-upload-progress-response-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ICourseUploadImportResult from "./course-upload-import-result-interface";

export default interface ICourseUploadProgressResponse {
jobId: string;
status: string;
message: string;
importResult: ICourseUploadImportResult;
};
3 changes: 3 additions & 0 deletions src/interfaces/export-course-request-body-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface IExportCourseRequestBody {
url: string;
};
3 changes: 3 additions & 0 deletions src/interfaces/export-course-response-interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default interface IExportCourseResponse {
result: string;
};
39 changes: 39 additions & 0 deletions src/models/courses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import ClientFactory from "../clients/clientFactory";
import IResponse from "../interfaces/response-interface";
import ICourseList from "../interfaces/rustici-course-list-interface";
import IExportCourseResponse from "../interfaces/export-course-response-interface";
import IExportCourseRequestBody from "../interfaces/export-course-request-body-interface";
import ICourseUploadProgressResponse from "../interfaces/course-upload-progress-response-interface";
import ILaunchLinkRequest from "../interfaces/rustici-launch-link-request-interface";
import ILaunchLink from "../interfaces/rustici-launch-link-interface";

export default class Courses {
private client: ClientFactory;
Expand All @@ -16,4 +21,38 @@ export default class Courses {
public async get(): Promise<IResponse<ICourseList>> {
return this.client.getRequest<ICourseList>('/courses');
}

/**
* Export the course into Rustici engine
* @param courseId
* @param body
* @param mayCreateNewVersion
* @returns {Promise<IResponse<IExportCourseResponse>>}
*/
public async exportCourse(courseId: string, body: IExportCourseRequestBody, mayCreateNewVersion: boolean = true): Promise<IResponse<IExportCourseResponse>> {
return this.client.postRequest<IExportCourseResponse>(
`/courses/importJobs?courseId=${courseId}&mayCreateNewVersion=${mayCreateNewVersion}`,
body,
);
}

/**
* Gets course upload progress
* @param importJobId
* @returns {Promise<IResponse<ICourseUploadProgressResponse>>}
*/
public async getCourseUploadProgress(importJobId: string): Promise<IResponse<ICourseUploadProgressResponse>> {
return this.client.getRequest<ICourseUploadProgressResponse>(`/courses/importJobs/${importJobId}`);
}

/**
* Gets the course preview link against
* course id.
* @param courseId
* @param body
* @returns { Promise<IResponse<ILaunchLink>> }
*/
public async getCoursePreviewLink(courseId: string, body: ILaunchLinkRequest): Promise<IResponse<ILaunchLink>> {
return this.client.postRequest(`/courses/${courseId}/preview`, body);
}
}
66 changes: 66 additions & 0 deletions tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,71 @@ describe('Index', () => {
await client.registrations.addWebhookSettings('987', configuration)
.then(() => expect(nock.isDone()));
});

it('exportCourse', async () => {
const expectedResult = { result: 'import-job-id' }
const body = { url: 'https://course-signed-url.com'}
const courseId = '1c5d2f1c-88f0-490f-9323-680b21a30e94';
const mayCreateNewVersion = true;
const path = `/courses/importJobs?courseId=${courseId}&mayCreateNewVersion=${mayCreateNewVersion}`;
const client = new RusticiSdk(undefined, config);

Nock(config.basePath)
.post(path)
.reply(200, expectedResult);


const response = await client.courses.exportCourse(courseId, body, mayCreateNewVersion);
expect(response).to.be.a('object');
expect(response).to.have.ownProperty('status');
expect(response).to.have.ownProperty('data');
expect(response.status).to.be.eql(200);
expect(response.data).to.be.a('object');
expect(response.data).to.have.ownProperty('result');
expect(response.data.result).to.be.a('string');
expect(response.data.result).to.be.eql('import-job-id');
});

it('getCourseUploadProgress', async () => {
const importJobId = 'import-job-id';
const expectedResult = { jobId: importJobId, status: 'RUNNING', message: 'random' };
const path = `/courses/importJobs/${importJobId}`;
const client = new RusticiSdk(undefined, config);

Nock(config.basePath)
.get(path)
.reply(200, expectedResult);

const response = await client.courses.getCourseUploadProgress(importJobId);
expect(response).to.be.a('object');
expect(response).to.have.ownProperty('status');
expect(response).to.have.ownProperty('data');
expect(response.status).to.be.eql(200);
expect(response.data).to.be.a('object');
expect(response.data).to.have.ownProperty('jobId');
expect(response.data.jobId).to.be.eql('import-job-id');
expect(response.data).to.have.ownProperty('status');
expect(response.data.status).to.be.eql('RUNNING');
expect(response.data).to.have.ownProperty('message');
expect(response.data.message).to.be.eql('random');
});

it('getCoursePreviewLink', async () => {
const courseId = '1c5d2f1c-88f0-490f-9323-680b21a30e94';
const body = { expiry: 10, redirectOnExitUrl: 'https:goiogle.com' };
const expectedResult = { launchLink: 'https://launch.url' };
const path = `/courses/${courseId}/preview`;
const client = new RusticiSdk(undefined, config);

Nock(config.basePath)
.post(path)
.reply(200, expectedResult);

const response = await client.courses.getCoursePreviewLink(courseId, body);
expect(response).to.have.ownProperty('status');
expect(response).to.have.ownProperty('data');
expect(response.status).to.be.eql(200);
expect(response.data.launchLink).to.be.eql('https://launch.url');
});
});
})

0 comments on commit 7c2b304

Please sign in to comment.