Skip to content

Commit

Permalink
Fixes create_policy_artifact_manifest pushArtifacts missing new manif…
Browse files Browse the repository at this point in the history
…est. Also fixes unit tests
  • Loading branch information
dasansol92 committed Jun 10, 2021
1 parent 101775a commit 14d2186
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([], newManifest);
expect(manifestManager.commit).not.toHaveBeenCalled();
expect(manifestManager.tryDispatch).toHaveBeenCalledWith(newManifest);
expect(manifestManager.deleteArtifacts).toHaveBeenCalledWith([]);
Expand All @@ -192,10 +192,10 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_TRUSTED_APPS_MACOS,
]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_TRUSTED_APPS_MACOS],
newManifest
);
expect(manifestManager.commit).not.toHaveBeenCalled();
expect(manifestManager.tryDispatch).not.toHaveBeenCalled();
expect(manifestManager.deleteArtifacts).not.toHaveBeenCalled();
Expand All @@ -221,10 +221,10 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_TRUSTED_APPS_MACOS,
]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_TRUSTED_APPS_MACOS],
newManifest
);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
expect(manifestManager.tryDispatch).not.toHaveBeenCalled();
expect(manifestManager.deleteArtifacts).not.toHaveBeenCalled();
Expand All @@ -251,10 +251,10 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_TRUSTED_APPS_MACOS,
]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_TRUSTED_APPS_MACOS],
newManifest
);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
expect(manifestManager.tryDispatch).toHaveBeenCalledWith(newManifest);
expect(manifestManager.deleteArtifacts).not.toHaveBeenCalled();
Expand Down Expand Up @@ -284,7 +284,10 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([ARTIFACT_TRUSTED_APPS_MACOS]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_TRUSTED_APPS_MACOS],
newManifest
);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
expect(manifestManager.tryDispatch).toHaveBeenCalledWith(newManifest);
expect(manifestManager.deleteArtifacts).toHaveBeenCalledWith([ARTIFACT_ID_1]);
Expand Down Expand Up @@ -314,7 +317,7 @@ describe('task', () => {

expect(manifestManager.getLastComputedManifest).toHaveBeenCalled();
expect(manifestManager.buildNewManifest).toHaveBeenCalledWith(lastManifest);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([], newManifest);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
expect(manifestManager.tryDispatch).toHaveBeenCalledWith(newManifest);
expect(manifestManager.deleteArtifacts).toHaveBeenCalledWith([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,13 @@ describe('ManifestManager', () => {
const context = buildManifestManagerContextMock({});
const artifactClient = context.artifactClient as jest.Mocked<EndpointArtifactClientInterface>;
const manifestManager = new ManifestManager(context);
const newManifest = ManifestManager.createDefaultManifest();

await expect(
manifestManager.pushArtifacts([ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_EXCEPTIONS_WINDOWS])
manifestManager.pushArtifacts(
[ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_EXCEPTIONS_WINDOWS],
newManifest
)
).resolves.toStrictEqual([]);

expect(artifactClient.createArtifact).toHaveBeenCalledTimes(2);
Expand All @@ -536,6 +540,7 @@ describe('ManifestManager', () => {
const context = buildManifestManagerContextMock({});
const artifactClient = context.artifactClient as jest.Mocked<EndpointArtifactClientInterface>;
const manifestManager = new ManifestManager(context);
const newManifest = ManifestManager.createDefaultManifest();
const error = new Error();
const { body, ...incompleteArtifact } = ARTIFACT_TRUSTED_APPS_MACOS;

Expand All @@ -550,11 +555,14 @@ describe('ManifestManager', () => {
);

await expect(
manifestManager.pushArtifacts([
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_EXCEPTIONS_WINDOWS,
incompleteArtifact as InternalArtifactCompleteSchema,
])
manifestManager.pushArtifacts(
[
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_EXCEPTIONS_WINDOWS,
incompleteArtifact as InternalArtifactCompleteSchema,
],
newManifest
)
).resolves.toStrictEqual([
error,
new Error(`Incomplete artifact: ${ARTIFACT_ID_TRUSTED_APPS_MACOS}`),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ describe('ingest_integration tests ', () => {
);

expect(manifestManager.buildNewManifest).toHaveBeenCalledWith();
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([ARTIFACT_EXCEPTIONS_MACOS]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS],
newManifest
);
expect(manifestManager.commit).not.toHaveBeenCalled();
});

Expand All @@ -170,7 +173,10 @@ describe('ingest_integration tests ', () => {
);

expect(manifestManager.buildNewManifest).toHaveBeenCalledWith();
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([ARTIFACT_EXCEPTIONS_MACOS]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS],
newManifest
);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
});

Expand All @@ -197,10 +203,10 @@ describe('ingest_integration tests ', () => {
);

expect(manifestManager.buildNewManifest).toHaveBeenCalledWith();
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith([
ARTIFACT_EXCEPTIONS_MACOS,
ARTIFACT_TRUSTED_APPS_MACOS,
]);
expect(manifestManager.pushArtifacts).toHaveBeenCalledWith(
[ARTIFACT_EXCEPTIONS_MACOS, ARTIFACT_TRUSTED_APPS_MACOS],
newManifest
);
expect(manifestManager.commit).toHaveBeenCalledWith(newManifest);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const getManifest = async (logger: Logger, manifestManager: ManifestManager): Pr

// Persist new artifacts
const persistErrors = await manifestManager.pushArtifacts(
newManifest.getAllArtifacts() as InternalArtifactCompleteSchema[]
newManifest.getAllArtifacts() as InternalArtifactCompleteSchema[],
newManifest
);
if (persistErrors.length) {
reportErrors(logger, persistErrors);
Expand Down

0 comments on commit 14d2186

Please sign in to comment.