-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1894 create
GET /jobs/:jobId/classifications/:value
- Loading branch information
1 parent
fddbebd
commit b9456bf
Showing
8 changed files
with
186 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
apps/api/src/cnn/get-classifier-job-info-by-classification-bll.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getClassifierJobInformation as coreGetClassifierJobInformation, getClassifierJobSummaryByClassification as coreGetClassifierJobSummaryByClassification } from '~/api-core/api-core' | ||
import { BioInvalidPathParamError } from '~/errors' | ||
|
||
export interface ClassifierJobByClassificationInformation { | ||
title: string | ||
total: number | ||
streams: Array<{ id: string, name: string }> | ||
} | ||
|
||
export const getClassifierJobInfoByClassification = async (token: string, jobId: string, classificationValue: string): Promise<ClassifierJobByClassificationInformation> => { | ||
if (jobId === undefined || jobId === '' || Number.isNaN(Number(jobId))) { | ||
throw BioInvalidPathParamError({ jobId }) | ||
} | ||
|
||
const [jobInfo, classificationInfo] = await Promise.all([ | ||
coreGetClassifierJobInformation(token, Number(jobId)), | ||
coreGetClassifierJobSummaryByClassification(token, Number(jobId), classificationValue) | ||
]) | ||
|
||
return { | ||
title: classificationInfo.title, | ||
total: classificationInfo.total, | ||
streams: jobInfo.streams | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
apps/api/src/cnn/get-classifier-job-info-by-classification-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { type GetClassifierJobInfoByClassificationParams, type GetClassifierJobInfoByClassificationResponse } from '@rfcx-bio/common/api-bio/cnn/classifier-job-classification' | ||
|
||
import { type Handler } from '~/api-helpers/types' | ||
import { getClassifierJobInfoByClassification } from './get-classifier-job-info-by-classification-bll' | ||
|
||
export const getClassifierJobInfoByClassificationHandler: Handler<GetClassifierJobInfoByClassificationResponse, GetClassifierJobInfoByClassificationParams> = async (req) => { | ||
const info = await getClassifierJobInfoByClassification(req.headers.authorization ?? '', req.params.jobId, req.params.classificationValue) | ||
return info | ||
} |
80 changes: 80 additions & 0 deletions
80
apps/api/src/cnn/get-classifier-job-info-by-classification.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { describe, expect, test, vi } from 'vitest' | ||
|
||
import { makeApp } from '@rfcx-bio/testing/handlers' | ||
|
||
import { routesCnn } from './index' | ||
|
||
const jobId = 101 | ||
const classificationValue = 'sciurus_carolinensis_simple_call_2' | ||
|
||
vi.mock('../_services/api-core/api-core') | ||
|
||
describe('GET /jobs/:jobId/classifications/:classificationValue', async () => { | ||
test('successfully get classification information by classification value', async () => { | ||
// Arrange | ||
const app = await makeApp(routesCnn, { | ||
projectRole: 'user', | ||
userToken: { | ||
email: 'rubygem1934@rfcx.org' | ||
} | ||
}) | ||
|
||
// Act | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: `/jobs/${jobId}/classifications/${classificationValue}` | ||
}) | ||
|
||
// Assert | ||
expect(response.statusCode).toEqual(200) | ||
const json = response.json() | ||
expect(json).toHaveProperty('title', 'Sciurus carolinensis, Simple call 2') | ||
expect(json).toHaveProperty('total', 1732) | ||
expect(json).toHaveProperty('streams', [ | ||
{ | ||
id: 'kdivmdkfogie', | ||
name: 'GU01' | ||
} | ||
]) | ||
}) | ||
|
||
test('non-rfcx member will get a 403', async () => { | ||
// Arrange | ||
const app = await makeApp(routesCnn, { | ||
projectRole: 'user', | ||
userToken: { | ||
email: 'rubygem1218@gmail.com' | ||
} | ||
}) | ||
|
||
// Act | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: `/jobs/${jobId}/classifications/${classificationValue}` | ||
}) | ||
|
||
// Assert | ||
expect(response.statusCode).toEqual(403) | ||
}) | ||
|
||
test('an invalid jobId (string) will result in 400', async () => { | ||
// Arrange | ||
const app = await makeApp(routesCnn, { | ||
projectRole: 'user', | ||
userToken: { | ||
email: 'rubygeme@rfcx.org' | ||
} | ||
}) | ||
|
||
// Act | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: `/jobs/who/classifications/${classificationValue}` | ||
}) | ||
|
||
console.info(response.body) | ||
|
||
// Assert | ||
expect(response.statusCode).toEqual(400) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/common/src/api-bio/cnn/classifier-job-classification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { type AxiosInstance } from 'axios' | ||
|
||
import { type GetClassifierJobInformationResponse } from './classifier-job-information' | ||
|
||
// Request types | ||
export interface GetClassifierJobInfoByClassificationParams { | ||
jobId: string | ||
classificationValue: string | ||
} | ||
|
||
// Response types | ||
export interface GetClassifierJobInfoByClassificationResponse { | ||
title: string | ||
total: number | ||
streams: GetClassifierJobInformationResponse['streams'] | ||
} | ||
|
||
// Route | ||
export const getClassifierJobInfoByClassificationRoute = '/jobs/:jobId/classifications/:classificationValue' | ||
|
||
// Service | ||
export const apiBioGetClassifierJobInfoByClassification = async (apiClient: AxiosInstance, jobId: number, classificationValue: string): Promise<GetClassifierJobInfoByClassificationResponse> => { | ||
const response = await apiClient.get(`/jobs/${jobId}/classifications/${classificationValue}`) | ||
return response.data | ||
} |