Skip to content

Commit

Permalink
fix: fixes an issue with adding nested linked data (#3092)
Browse files Browse the repository at this point in the history
  • Loading branch information
janechu authored May 11, 2020
1 parent ecbadec commit fa5630a
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 120 deletions.
22 changes: 5 additions & 17 deletions packages/tooling/fast-tooling/src/message-system/data.props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface LinkedDataPromise {
/**
* The data location this promised linked data should go
*/
linkedDataLocation?: string;
dataLocation?: string;

/**
* The linked data to add to this piece of linked data
Expand All @@ -56,9 +56,9 @@ export interface Data<T> {
data: T;

/**
* The data location for the linked data
* The data location this linked data should go
*/
linkedDataLocation?: string;
dataLocation?: string;

/**
* The linked data to add to this piece of linked data
Expand Down Expand Up @@ -88,11 +88,6 @@ export interface LinkedDataDictionaryConfig {
* The root dictionary ID
*/
dictionaryId: string;

/**
* The root data location
*/
dataLocation: string;
}

export interface LinkedDataDictionaryUpdate {
Expand All @@ -102,14 +97,7 @@ export interface LinkedDataDictionaryUpdate {
dataDictionary: DataDictionary<unknown>;

/**
* The IDs to be added to the dictionaryId at the data location
* The dictionary ID to add the root of this data dictionary to
*/
linkedDataIds: LinkedData[];
}

export interface ResolveDataDictionary {
/**
* The new data dictionary
*/
dataDictionary: { [key: string]: Data<unknown> };
dictionaryId: string;
}
154 changes: 116 additions & 38 deletions packages/tooling/fast-tooling/src/message-system/data.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getLinkedDataDictionary } from "./data";
import { LinkedDataPromise } from "./data.props";
import { LinkedDataDictionaryUpdate, LinkedDataPromise } from "./data.props";

describe("getLinkedDataDictionary", () => {
test("should get a linked data dictionary", () => {
const root: string = "rootLocation";
const dictionaryId: string = "root";
const dataLocation: string = "foo";
const schemaId: string = "foobar";
const data: any = {
Expand All @@ -16,10 +16,10 @@ describe("getLinkedDataDictionary", () => {
{
schemaId,
data,
dataLocation,
},
],
dictionaryId: root,
dataLocation,
dictionaryId,
})
).toEqual({
dataDictionary: [
Expand All @@ -28,23 +28,18 @@ describe("getLinkedDataDictionary", () => {
schemaId,
data,
parent: {
id: root,
id: dictionaryId,
dataLocation,
},
items: [],
},
},
root,
"fast1",
],
linkedDataIds: [
{
id: "fast1",
},
],
});
dictionaryId,
} as LinkedDataDictionaryUpdate);
});
test("should get a linked data dictionary with nested linked data", () => {
const root: string = "rootLocation";
const dictionaryId: string = "root";
const dataLocation: string = "foo";
const schemaId: string = "foobar";
const data: any = {
Expand All @@ -57,14 +52,15 @@ describe("getLinkedDataDictionary", () => {
data: {
foo: "bar",
},
dataLocation: nestedLinkedDataLocation,
};
const nestedLinkedData: LinkedDataPromise = {
schemaId: "bar",
data: {
hello: "pluto",
},
linkedData: [nestedNestedLinkedData, nestedNestedLinkedData],
linkedDataLocation: nestedLinkedDataLocation,
dataLocation: linkedDataLocation,
};

expect(
Expand All @@ -73,33 +69,47 @@ describe("getLinkedDataDictionary", () => {
{
schemaId,
data,
linkedDataLocation,
dataLocation,
linkedData: [nestedLinkedData],
},
],
dictionaryId: root,
dataLocation,
dictionaryId,
})
).toEqual({
dataDictionary: [
{
fast2: {
schemaId,
data,
data: {
...data,
[linkedDataLocation]: [
{
id: "fast3",
},
],
},
parent: {
id: root,
id: dictionaryId,
dataLocation,
},
items: ["fast3"],
},
fast3: {
schemaId: nestedLinkedData.schemaId,
data: nestedLinkedData.data,
data: {
...(nestedLinkedData.data as any),
[nestedLinkedDataLocation]: [
{
id: "fast4",
},
{
id: "fast5",
},
],
},
parent: {
id: "fast2",
dataLocation: linkedDataLocation,
},
items: ["fast4", "fast5"],
},
fast4: {
schemaId: nestedNestedLinkedData.schemaId,
Expand All @@ -108,7 +118,6 @@ describe("getLinkedDataDictionary", () => {
id: "fast3",
dataLocation: nestedLinkedDataLocation,
},
items: [],
},
fast5: {
schemaId: nestedNestedLinkedData.schemaId,
Expand All @@ -117,25 +126,94 @@ describe("getLinkedDataDictionary", () => {
id: "fast3",
dataLocation: nestedLinkedDataLocation,
},
items: [],
},
},
root,
"fast2",
],
linkedDataIds: [
{
id: "fast2",
},
{
id: "fast3",
},
{
id: "fast4",
},
dictionaryId,
} as LinkedDataDictionaryUpdate);
});
test("should get a linked data dictionary with multiple nested linked data", () => {
const dictionaryId: string = "root";
const dataLocation: string = "foo";
const schemaId: string = "foobar";
const data: any = {
hello: "world",
};
const linkedDataLocation1: string = "a";
const linkedDataLocation2: string = "b";
const nestedNestedLinkedData1: LinkedDataPromise = {
schemaId: "bar",
data: {
foo: "bar",
},
dataLocation: linkedDataLocation1,
};
const nestedNestedLinkedData2: LinkedDataPromise = {
schemaId: "foo",
data: {
foo: "bat",
},
dataLocation: linkedDataLocation2,
};

expect(
getLinkedDataDictionary({
linkedData: [
{
schemaId,
data,
dataLocation,
linkedData: [nestedNestedLinkedData1, nestedNestedLinkedData2],
},
],
dictionaryId,
})
).toEqual({
dataDictionary: [
{
id: "fast5",
fast6: {
schemaId,
data: {
...data,
[linkedDataLocation1]: [
{
id: "fast7",
},
],
[linkedDataLocation2]: [
{
id: "fast8",
},
],
},
parent: {
id: dictionaryId,
dataLocation,
},
},
fast7: {
schemaId: nestedNestedLinkedData1.schemaId,
data: {
...(nestedNestedLinkedData1.data as any),
},
parent: {
id: "fast6",
dataLocation: linkedDataLocation1,
},
},
fast8: {
schemaId: nestedNestedLinkedData2.schemaId,
data: nestedNestedLinkedData2.data,
parent: {
id: "fast6",
dataLocation: linkedDataLocation2,
},
},
},
"fast6",
],
});
dictionaryId,
} as LinkedDataDictionaryUpdate);
});
});
Loading

0 comments on commit fa5630a

Please sign in to comment.