Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(test): Add unit tests for aicore-clients #12

Merged
merged 16 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 47 additions & 18 deletions packages/ai-core/src/application-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,106 +24,135 @@ export const ApplicationApi = {
* Return all Argo CD application data objects.
*
* @param queryParameters - Object containing the following keys: $top, $skip, $count.
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsGetAll: (queryParameters?: {
$top?: number;
$skip?: number;
$count?: boolean;
}) =>
kubesubmitV4ApplicationsGetAll: (
queryParameters?: { $top?: number; $skip?: number; $count?: boolean },
headerParameters?: { Authorization?: string }
shibeshduw marked this conversation as resolved.
Show resolved Hide resolved
) =>
new OpenApiRequestBuilder<AllArgoCDApplicationData>(
'get',
'/admin/applications',
{
queryParameters
queryParameters,
headerParameters
}
),
/**
* Create an ArgoCD application to synchronise a repository.
*
* @param body - Request body.
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsCreate: (body: Body) =>
kubesubmitV4ApplicationsCreate: (
body: Body,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationCreationResponse>(
'post',
'/admin/applications',
{
body
body,
headerParameters
}
),
/**
* Returns the ArgoCD application health and sync status.
*
* @param applicationName - Name of the ArgoCD application
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsGetStatus: (applicationName: string) =>
kubesubmitV4ApplicationsGetStatus: (
applicationName: string,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationStatus>(
'get',
'/admin/applications/{applicationName}/status',
{
pathParameters: { applicationName }
pathParameters: { applicationName },
headerParameters
}
),
/**
* Retrieve the ArgoCD application details.
*
* @param applicationName - Name of the ArgoCD application
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsGet: (applicationName: string) =>
kubesubmitV4ApplicationsGet: (
applicationName: string,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationData>(
'get',
'/admin/applications/{applicationName}',
{
pathParameters: { applicationName }
pathParameters: { applicationName },
headerParameters
}
),
/**
* Update the referenced ArgoCD application to synchronize the repository.
*
* @param applicationName - Name of the ArgoCD application
* @param body - Request body.
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsUpdate: (
applicationName: string,
body: ArgoCDApplicationBaseData
body: ArgoCDApplicationBaseData,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationModificationResponse>(
'patch',
'/admin/applications/{applicationName}',
{
pathParameters: { applicationName },
body
body,
headerParameters
}
),
/**
* Delete an ArgoCD application
* @param applicationName - Name of the ArgoCD application
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsDelete: (applicationName: string) =>
kubesubmitV4ApplicationsDelete: (
applicationName: string,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationDeletionResponse>(
'delete',
'/admin/applications/{applicationName}',
{
pathParameters: { applicationName }
pathParameters: { applicationName },
headerParameters
}
),
/**
* Schedules a refresh of the specified application that will be picked up by ArgoCD asynchronously
*
* @param applicationName - Name of the ArgoCD application
* @param headerParameters - Object containing the following keys: Authorization.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
kubesubmitV4ApplicationsRefresh: (applicationName: string) =>
kubesubmitV4ApplicationsRefresh: (
applicationName: string,
headerParameters?: { Authorization?: string }
) =>
new OpenApiRequestBuilder<ArgoCDApplicationRefreshResponse>(
'post',
'/admin/applications/{applicationName}/refresh',
{
pathParameters: { applicationName }
pathParameters: { applicationName },
headerParameters
}
)
};
86 changes: 86 additions & 0 deletions packages/ai-core/src/artifact-api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import nock from 'nock';
import { HttpDestination } from '@sap-cloud-sdk/connectivity';
import {
ArtifactApi,
ArtifactCreationResponse,
ArtifactList,
ArtifactPostData
} from './index.js';

describe('artifact', () => {
const destination: HttpDestination = {
url: 'https://ai.example.com'
};

afterEach(() => {
nock.cleanAll();
});

it('parses a successful response for get request', async () => {
const expectedResponse: ArtifactList = {
count: 1,
resources: [
{
createdAt: '2024-07-08T13:36:41Z',
description: 'dataset for training test',
id: '0a1b2c3d',
kind: 'dataset',
modifiedAt: '2024-07-08T13:36:41Z',
name: 'training-test-data',
scenarioId: 'foundation-models',
url: 'ai://default/spam/data'
}
]
};

nock(destination.url, {
reqheaders: {
'AI-Resource-Group': 'default'
}
})
.get('/lm/artifacts')
.reply(200, expectedResponse, {
'Content-Type': 'application/json'
});

const result: ArtifactList = await ArtifactApi.artifactQuery(
{},
{ 'AI-Resource-Group': 'default' }
).execute(destination);

expect(result).toEqual(expectedResponse);
});

it('parses a successful response for post request', async () => {
const expectedResponse: ArtifactCreationResponse = {
id: '3d2c1b0a',
message: 'Artifact acknowledged',
url: 'ai://default/spam/data'
};

nock(destination.url, {
reqheaders: {
'AI-Resource-Group': 'default'
}
})
.post('/lm/artifacts')
.reply(200, expectedResponse, {
'Content-Type': 'application/json'
});

const artifactPostData: ArtifactPostData = {
description: 'dataset for training test',
kind: 'dataset',
name: 'training-test-data',
scenarioId: 'foundation-models',
url: 'ai://default/spam/data'
};

const result: ArtifactCreationResponse = await ArtifactApi.artifactCreate(
artifactPostData,
{ 'AI-Resource-Group': 'default' }
).execute(destination);

expect(result).toEqual(expectedResponse);
});
});
72 changes: 45 additions & 27 deletions packages/ai-core/src/artifact-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,68 +23,86 @@ export const ArtifactApi = {
* Search by substring of artifact name or description, if required.
*
* @param queryParameters - Object containing the following keys: scenarioId, executionId, name, kind, artifactLabelSelector, $top, $skip, $search, searchCaseInsensitive, $expand.
* @param headerParameters - Object containing the following keys: AI-Resource-Group.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
artifactQuery: (queryParameters?: {
scenarioId?: string;
executionId?: string;
name?: Name_1;
kind?: 'model' | 'dataset' | 'resultset' | 'other';
artifactLabelSelector?: string[];
$top?: number;
$skip?: number;
$search?: string;
searchCaseInsensitive?: boolean;
$expand?: 'scenario';
}) =>
artifactQuery: (
shibeshduw marked this conversation as resolved.
Show resolved Hide resolved
queryParameters: {
scenarioId?: string;
executionId?: string;
name?: Name_1;
kind?: 'model' | 'dataset' | 'resultset' | 'other';
artifactLabelSelector?: string[];
$top?: number;
$skip?: number;
$search?: string;
searchCaseInsensitive?: boolean;
$expand?: 'scenario';
},
headerParameters: { 'AI-Resource-Group': string }
) =>
new OpenApiRequestBuilder<ArtifactList>('get', '/lm/artifacts', {
queryParameters
queryParameters,
headerParameters
}),
/**
* Register an artifact for use in a configuration, for example a model or a dataset.
* @param body - Request body.
* @param headerParameters - Object containing the following keys: AI-Resource-Group.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
artifactCreate: (body: ArtifactPostData) =>
artifactCreate: (
body: ArtifactPostData,
headerParameters: { 'AI-Resource-Group': string }
) =>
new OpenApiRequestBuilder<ArtifactCreationResponse>(
'post',
'/lm/artifacts',
{
body
body,
headerParameters
}
),
/**
* Retrieve details for artifact with artifactId.
* @param artifactId - Artifact identifier
* @param queryParameters - Object containing the following keys: $expand.
* @param headerParameters - Object containing the following keys: AI-Resource-Group.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
artifactGet: (
artifactId: string,
queryParameters?: { $expand?: 'scenario' }
queryParameters: { $expand?: 'scenario' },
headerParameters: { 'AI-Resource-Group': string }
) =>
new OpenApiRequestBuilder<Artifact>('get', '/lm/artifacts/{artifactId}', {
pathParameters: { artifactId },
queryParameters
queryParameters,
headerParameters
}),
/**
* Retrieve the number of available artifacts that match the specified filter criteria.
* Filter criteria include a scenarioId, executionId, an artifact name, artifact kind, or artifact labels.
* Search by substring of artifact name or description is also possible.
*
* @param queryParameters - Object containing the following keys: scenarioId, executionId, name, kind, $search, searchCaseInsensitive, artifactLabelSelector.
* @param headerParameters - Object containing the following keys: AI-Resource-Group.
* @returns The request builder, use the `execute()` method to trigger the request.
*/
artifactCount: (queryParameters?: {
scenarioId?: string;
executionId?: string;
name?: Name_1;
kind?: 'model' | 'dataset' | 'resultset' | 'other';
$search?: string;
searchCaseInsensitive?: boolean;
artifactLabelSelector?: string[];
}) =>
artifactCount: (
queryParameters: {
scenarioId?: string;
executionId?: string;
name?: Name_1;
kind?: 'model' | 'dataset' | 'resultset' | 'other';
$search?: string;
searchCaseInsensitive?: boolean;
artifactLabelSelector?: string[];
},
headerParameters: { 'AI-Resource-Group': string }
) =>
new OpenApiRequestBuilder<any>('get', '/lm/artifacts/$count', {
queryParameters
queryParameters,
headerParameters
})
};
Loading
Loading