Skip to content

Commit

Permalink
Adapt dataplanes response body
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt committed Sep 26, 2023
1 parent 3e0a7c0 commit 0a7d24e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { EdcConnectorClientContext } from "../../context";
import {
expand,
expandArray,
Dataplane,
DataplaneInput,
IdResponse,
EDC_CONTEXT,
} from "../../entities";
import { Inner } from "../../inner";
Expand All @@ -22,7 +24,7 @@ export class DataplaneController {
async register(
input: DataplaneInput,
context?: EdcConnectorClientContext,
): Promise<void> {
): Promise<IdResponse> {
const actualContext = context || this.#context!;

return this.#inner.request(actualContext.management, {
Expand All @@ -33,12 +35,13 @@ export class DataplaneController {
...input,
"@context": this.defaultContextValues,
},
});
})
.then((body) => expand(body, () => new IdResponse()));
}

async list(context?: EdcConnectorClientContext): Promise<Dataplane[]> {
const actualContext = context || this.#context!;

return this.#inner
.request(actualContext.management, {
path: "/v2/dataplanes",
Expand Down
9 changes: 6 additions & 3 deletions tests/controllers/management-tests/dataplanes.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as crypto from "node:crypto";
import { EdcConnectorClient } from "../../../src";

describe("DataplaneController", () => {
Expand All @@ -12,8 +13,9 @@ describe("DataplaneController", () => {

describe("register", () => {
it("succesfully register a dataplane", async () => {
const id = crypto.randomUUID();
const input = {
id: "consumer-dataplane",
"@id": id,
url: "http://provider-connector:9192/control/transfer",
allowedSourceTypes: ["HttpData"],
allowedDestTypes: ["HttpProxy", "HttpData"],
Expand All @@ -22,9 +24,10 @@ describe("DataplaneController", () => {
},
};

const registration = await dataplanes.register(input);
const idResponse = await dataplanes.register(input);

expect(registration).toBeUndefined();
expect(idResponse.id).toBe(id);
expect(idResponse.createdAt).toBeGreaterThan(0);
});
});

Expand Down

0 comments on commit 0a7d24e

Please sign in to comment.