Skip to content

Commit

Permalink
fix(models): list asset returns commons assets (#345)
Browse files Browse the repository at this point in the history
* chore(models): expose listAssets bug

* fix(models): listAssets now returns commons asset on engines

* chore: lint

* chore: apply review on test case
  • Loading branch information
Juiced66 authored Jun 19, 2024
1 parent d209269 commit 2844437
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/modules/model/ModelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,17 @@ export class ModelService extends BaseService {
engineGroup: string,
): Promise<KDocument<AssetModelContent>[]> {
const query = {
and: [{ equals: { type: "asset" } }, { equals: { engineGroup } }],
and: [
{ equals: { type: "asset" } },
{
or: [
{ equals: { engineGroup } },
{ equals: { engineGroup: "commons" } },
],
},
],
};

const sort = { "asset.model": "asc" };

const result = await this.sdk.document.search<AssetModelContent>(
Expand Down
28 changes: 27 additions & 1 deletion tests/scenario/migrated/model-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe("features/Model/Controller", () => {
},
},
});

response = await sdk.query({
controller: "device-manager/models",
action: "writeAsset",
Expand Down Expand Up @@ -127,6 +126,33 @@ describe("features/Model/Controller", () => {
await expect(promise).rejects.toMatchObject({ status: 404 });
});

it("List on an engine is also returning commons assets models", async () => {
await sdk.query({
controller: "device-manager/models",
action: "writeAsset",
body: {
engineGroup: "other-group",
model: "Car",
},
});

const response = await sdk.query({
controller: "device-manager/models",
action: "listAssets",
engineGroup: "other-group",
});

expect(response.result).toMatchObject({
total: 4,
models: [
{ _id: "model-asset-Car" },
{ _id: "model-asset-Container" },
{ _id: "model-asset-Plane" },
{ _id: "model-asset-Warehouse" },
],
});
});

it("Create an asset with default metadata values", async () => {
let response;
let promise;
Expand Down

0 comments on commit 2844437

Please sign in to comment.