Skip to content

Commit 29af0d0

Browse files
committed
feat: added model param and remove jobIdentifier params on jobHistory
1 parent ea4beb1 commit 29af0d0

File tree

2 files changed

+130
-78
lines changed

2 files changed

+130
-78
lines changed

src/job-client.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class JobClient{
2626
* @param {string} access_key - Identifier of the access key to be assigned to the user
2727
* @param {(Date|string)} start_date - initial date to filter recods
2828
* @param {(Date|string)} end_date - final date to filter recods
29-
* @param {(string|string[])} job_identifiers - Array of unique job identifiers
29+
* @param {string} model - model name or version
3030
* @param {string} status - Status of the jobs (all, pending, terminated)
3131
* @param {string} sortBy - attribute name to sort results
3232
* @param {string} direction - Direction of the sorting algorithm (asc, desc)
@@ -36,7 +36,7 @@ class JobClient{
3636
* @throws {ApiError} Error if there is something wrong with the service or the call
3737
*/
3838
getJobHistory(user, accessKey, startDate, endDate,
39-
jobIdentifiers, status,
39+
model, status,
4040
page, perPage=1000, direction, sortBy
4141
){
4242
if( user !== null && typeof user !== "string" ){
@@ -46,7 +46,7 @@ class JobClient{
4646
throw("the accessKey param should be a string");
4747
}
4848
if( startDate !== null && startDate !== undefined ){
49-
if( typeof startDate === "Date" ){
49+
if( startDate instanceof Date ){
5050
startDate = startDate.toISOString();
5151
}
5252
else if( typeof startDate !== "string" ){
@@ -64,9 +64,9 @@ class JobClient{
6464
if( status !== null && typeof status !== "string" ){
6565
throw("the status param should be a string");
6666
}
67-
if(jobIdentifiers !== null && jobIdentifiers.length !== undefined ){
68-
throw("the jobIdentifiers param should be a array");
69-
}
67+
if( model !== null && typeof model !== "string" ){
68+
throw("the model param should be a string");
69+
}
7070
if( sortBy !== null && typeof sortBy !== "string" ){
7171
throw("the sortBy param should be a string");
7272
}
@@ -84,7 +84,7 @@ class JobClient{
8484
"accessKey": accessKey,
8585
"startDate": startDate,
8686
"endDate": endDate,
87-
"jobIdentifiers": jobIdentifiers,
87+
"model": model,
8888
"status": status,
8989
"sort-by": sortBy,
9090
"direction": direction,

tests/job-client.test.js

Lines changed: 123 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,6 @@ import JobClient from '../src/job-client.js';
55

66
const jobClient = new JobClient(process.env.MODZY_BASE_URL, process.env.MODZY_API_KEY);
77

8-
test(
9-
'testGetJobHistoryStatusAll',
10-
async () => {
11-
await jobClient.getJobHistory(null, null, null, null, null, 'all', null, null, null, null)
12-
.then(
13-
(jobs) => {
14-
expect(jobs).toBeDefined();
15-
expect(jobs).not.toHaveLength(0);
16-
logger.info( `testGetJobHistoryStatusAll() get ${jobs.length} jobs` );
17-
jobs.forEach(
18-
(job)=>{
19-
expect(job.jobIdentifier).toBeDefined();
20-
expect(job.status).toBeDefined();
21-
expect(job.submittedAt).toBeDefined();
22-
expect(job.submittedBy).toBeDefined();
23-
}
24-
);
25-
}
26-
);
27-
}
28-
);
29-
30-
test(
31-
'testGetJobHistoryByUser',
32-
async () => {
33-
await jobClient.getJobHistory(process.env.MODZY_API_KEY.substring(0,process.env.MODZY_API_KEY.lastIndexOf('.')), null, null, null, null, 'all', null, null, null, null)
34-
.then(
35-
(jobs) => {
36-
expect(jobs).toBeDefined();
37-
expect(jobs).not.toHaveLength(0);
38-
logger.info( `testGetJobHistoryByUser() get ${jobs.length} jobs` );
39-
jobs.forEach(
40-
(job)=>{
41-
expect(job.jobIdentifier).toBeDefined();
42-
expect(job.status).toBeDefined();
43-
expect(job.submittedAt).toBeDefined();
44-
expect(job.submittedBy).toBeDefined();
45-
}
46-
);
47-
}
48-
);
49-
}
50-
);
51-
52-
test(
53-
'testGetJobHistoryByAccessKey',
54-
async () => {
55-
await jobClient.getJobHistory(null, process.env.MODZY_API_KEY.substring(0,process.env.MODZY_API_KEY.lastIndexOf('.')), null, null, null, null, null, null, null, null)
56-
.then(
57-
(jobs) => {
58-
expect(jobs).toBeDefined();
59-
expect(jobs).not.toHaveLength(0);
60-
logger.info( `testGetJobHistoryByAccessKey() get ${jobs.length} jobs` );
61-
jobs.forEach(
62-
(job)=>{
63-
expect(job.jobIdentifier).toBeDefined();
64-
expect(job.status).toBeDefined();
65-
expect(job.submittedAt).toBeDefined();
66-
expect(job.submittedBy).toBeDefined();
67-
}
68-
);
69-
}
70-
)
71-
.catch(
72-
(error)=>{
73-
logger.error("Error: "+error);
74-
}
75-
);
76-
}
77-
);
78-
798
test(
809
'testSubmitJob',
8110
async () => {
@@ -207,4 +136,127 @@ test(
207136
}
208137
);
209138

139+
test(
140+
'testGetJobHistoryByUser',
141+
async () => {
142+
await jobClient.getJobHistory("a", null, null, null, null, null, null, null, null, null)
143+
.then(
144+
(jobs) => {
145+
expect(jobs).toBeDefined();
146+
expect(jobs).not.toHaveLength(0);
147+
logger.info( `testGetJobHistorybyUser() get ${jobs.length} jobs` );
148+
jobs.forEach(
149+
(job)=>{
150+
expect(job.jobIdentifier).toBeDefined();
151+
expect(job.status).toBeDefined();
152+
expect(job.submittedAt).toBeDefined();
153+
expect(job.submittedBy).toBeDefined();
154+
}
155+
);
156+
}
157+
);
158+
}
159+
);
160+
161+
test(
162+
'testGetJobHistoryByModel',
163+
async () => {
164+
await jobClient.getJobHistory(null, null, null, null, "Sentiment Analysis", null, null, null, null, null)
165+
.then(
166+
(jobs) => {
167+
expect(jobs).toBeDefined();
168+
expect(jobs).not.toHaveLength(0);
169+
logger.info( `testGetJobHistoryByModel() get ${jobs.length} jobs` );
170+
jobs.forEach(
171+
(job)=>{
172+
expect(job.jobIdentifier).toBeDefined();
173+
expect(job.status).toBeDefined();
174+
expect(job.submittedAt).toBeDefined();
175+
expect(job.submittedBy).toBeDefined();
176+
}
177+
);
178+
}
179+
);
180+
}
181+
);
182+
183+
test(
184+
'testGetJobHistoryByAccessKey',
185+
async () => {
186+
await jobClient.getJobHistory(null, process.env.MODZY_API_KEY.substring(0,process.env.MODZY_API_KEY.lastIndexOf('.')), null, null, null, null, null, null, null, null)
187+
.then(
188+
(jobs) => {
189+
expect(jobs).toBeDefined();
190+
expect(jobs).not.toHaveLength(0);
191+
logger.info( `testGetJobHistoryByAccessKey() get ${jobs.length} jobs` );
192+
jobs.forEach(
193+
(job)=>{
194+
expect(job.jobIdentifier).toBeDefined();
195+
expect(job.status).toBeDefined();
196+
expect(job.submittedAt).toBeDefined();
197+
expect(job.submittedBy).toBeDefined();
198+
}
199+
);
200+
}
201+
)
202+
.catch(
203+
(error)=>{
204+
logger.error("Error: "+error);
205+
}
206+
);
207+
}
208+
);
209+
210+
test(
211+
'testGetJobHistoryByDate',
212+
async () => {
213+
let startDate = new Date();
214+
startDate.setDate(startDate.getDate()-7);
215+
logger.info("StartDate type "+(startDate instanceof Date))
216+
await jobClient.getJobHistory(null, null, startDate, null, null, null, null, null, null, null)
217+
.then(
218+
(jobs) => {
219+
expect(jobs).toBeDefined();
220+
expect(jobs).not.toHaveLength(0);
221+
logger.info( `testGetJobHistoryByDate() get ${jobs.length} jobs` );
222+
jobs.forEach(
223+
(job)=>{
224+
expect(job.jobIdentifier).toBeDefined();
225+
expect(job.status).toBeDefined();
226+
expect(job.submittedAt).toBeDefined();
227+
expect(job.submittedBy).toBeDefined();
228+
}
229+
);
230+
}
231+
);
232+
}
233+
);
234+
235+
test(
236+
'testGetJobHistoryStatus',
237+
async () => {
238+
await jobClient.getJobHistory(null, null, null, null, null, 'terminated', null, null, null, null)
239+
.then(
240+
(jobs) => {
241+
expect(jobs).toBeDefined();
242+
expect(jobs).not.toHaveLength(0);
243+
logger.info( `testGetJobHistoryStatus() get ${jobs.length} jobs` );
244+
jobs.forEach(
245+
(job)=>{
246+
expect(job.jobIdentifier).toBeDefined();
247+
expect(job.status).toBeDefined();
248+
expect(job.submittedAt).toBeDefined();
249+
expect(job.submittedBy).toBeDefined();
250+
}
251+
);
252+
}
253+
);
254+
}
255+
);
256+
257+
258+
259+
260+
261+
210262

0 commit comments

Comments
 (0)