Skip to content

Commit

Permalink
feat: Add a public method to retrieve the artifact metadata for a giv…
Browse files Browse the repository at this point in the history
…en artifact directory (#18)
  • Loading branch information
marcelschork committed Mar 16, 2023
1 parent eb5ae11 commit edd8381
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ The available APIActions are: `Create`, `Read`, `Update`, `Delete` and `New_Vers
const artifactType = sciRestClient.getArtifactType('<pathToArtifactDirectory>');
```

#### Get artifact artifact metadata

```js
const artifactMetadata = sciRestClient.getArtifactMetadata('<pathToArtifactDirectory>');
```

Returns an object containing the id, name, version and type of the artifact in the specified directory.

# Test

The package is implemented in TypeScript and [Vitest](https://vitest.dev/) is used as a test framework. The tests need to run against a real Integration content API endpoint. The API endpoint and the credentials are read from environment variables. For executing the tests create a `.env`file inside the root directory of the package
Expand Down
14 changes: 14 additions & 0 deletions src/lib/client/SCIRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export default class SCIRestClient {
* @param {string} artifactVersion - The version of the artifact.
* @param {ArtifactType} artifactType - The type of the artifact.
*
* @returns {Promise<fs.ReadStream | void>} - A read stream for the artifact or void if an error occurred.
*
*/
async getArtifact(artifactId: string, artifactVersion: string, artifactType: ArtifactType): Promise<fs.ReadStream | void> {
log.info(`Reading artifact ${artifactId}...`);
Expand Down Expand Up @@ -364,6 +366,18 @@ export default class SCIRestClient {
return manifestReader.getArtifactMetadata().Type;
}

/**
* Returns the metadata of the artifact in the given directory.
*
* @param {string} artifactDirectoryPath - Path to the directory containing the artifact.
*
* @returns {Artifact} - The metadata of the artifact.
*/
public getArtifactMetadata(artifactDirectoryPath: string) {
const manifestReader = new ManifestReader(artifactDirectoryPath);
return manifestReader.getArtifactMetadata();
}

private invalidateCSRFToken() {
this.csrfToken = '';
this.cookie = [];
Expand Down
7 changes: 7 additions & 0 deletions src/test/integration/IntegrationFlow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ describe('Integration flow', () => {
expect(sciRestClient.isActionSupported(APIAction.New_Version, iFlowDirectory)).toBe(true);
expect(sciRestClient.isActionSupported(APIAction.Delete, iFlowDirectory)).toBe(false);
});

it('provides the metadata for the artifact in the given directory', () => {
expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Id).toBe('IntegrationFlow');
expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Version).toBe('2.0.0');
expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Name).toBe('Integration Flow');
expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Type).toBe('IntegrationFlow');
});
});
7 changes: 7 additions & 0 deletions src/test/integration/MessageMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ describe('Message mapping', () => {
expect(sciRestClient.isActionSupported(APIAction.New_Version, messageMappingDirectory)).toBe(true);
expect(sciRestClient.isActionSupported(APIAction.Delete, messageMappingDirectory)).toBe(false);
});

it('provides the metadata for the artifact in the given directory', () => {
expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Id).toBe('MessageMapping');
expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Version).toBe('2.0.0');
expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Name).toBe('MessageMapping');
expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Type).toBe('MessageMapping');
});
});
7 changes: 7 additions & 0 deletions src/test/integration/ScriptCollection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ describe('Script collection', () => {
expect(sciRestClient.isActionSupported(APIAction.New_Version, scriptCollectionDirectory)).toBe(true);
expect(sciRestClient.isActionSupported(APIAction.Delete, scriptCollectionDirectory)).toBe(false);
});

it('provides the metadata for the artifact in the given directory', () => {
expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Id).toBe('ScriptCollection');
expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Version).toBe('2.0.0');
expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Name).toBe('ScriptCollection');
expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Type).toBe('ScriptCollection');
});
});
7 changes: 7 additions & 0 deletions src/test/integration/ValueMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ describe('Value mapping', () => {
expect(sciRestClient.isActionSupported(APIAction.New_Version, valueMappingDirectory)).toBe(true);
expect(sciRestClient.isActionSupported(APIAction.Delete, valueMappingDirectory)).toBe(false);
});

it('provides the metadata for the artifact in the given directory', () => {
expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Id).toBe('ValueMapping');
expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Version).toBe('1.0.0');
expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Name).toBe('ValueMapping');
expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Type).toBe('ValueMapping');
});
});

0 comments on commit edd8381

Please sign in to comment.