-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ensure sites have telemetry (#1430)
- Loading branch information
Showing
7 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ const DEFAULT_SITE: Partial<IHubSite> = { | |
feedback: true, | ||
}, | ||
}, | ||
telemetry: {}, | ||
}; | ||
|
||
/** | ||
|
25 changes: 25 additions & 0 deletions
25
packages/common/src/sites/_internal/ensureBaseTelemetry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { getProp } from "../../objects"; | ||
import { IDraft, IModel } from "../../types"; | ||
import { cloneObject } from "../../util"; | ||
|
||
/** | ||
* During a period in late 2023 and early 2024, the python api | ||
* was writing a bad confirmation for basemaps as part of the site | ||
* cloning process. This migration will fix that. | ||
* @param {Object} model Site Model | ||
* @private | ||
*/ | ||
export function ensureBaseTelemetry<T extends IModel | IDraft>(model: T) { | ||
// Unlike other migrations, this is not based on a version | ||
// rather it checks for a missing telemetry property. | ||
|
||
// Early exit if the telemetry is there | ||
if (getProp(model, "data.telemetry")) { | ||
return model; | ||
} | ||
|
||
const clone = cloneObject(model); | ||
clone.data.telemetry = {}; | ||
|
||
return clone; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/common/test/sites/_internal/ensureBaseTelemetry.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IModel } from "../../../src"; | ||
import { ensureBaseTelemetry } from "../../../src/sites/_internal/ensureBaseTelemetry"; | ||
|
||
describe("ensure base telemtry:", () => { | ||
it("returns model if telemetry is present", () => { | ||
const model: IModel = { | ||
data: { | ||
telemetry: {}, | ||
}, | ||
} as unknown as IModel; | ||
const chk = ensureBaseTelemetry(model); | ||
expect(chk).toBe(model); | ||
}); | ||
|
||
it("returns clone with telemetry when telemetry is not present", () => { | ||
const model: IModel = { | ||
data: {}, | ||
} as unknown as IModel; | ||
const chk = ensureBaseTelemetry(model); | ||
expect(chk).not.toBe(model); | ||
expect(chk?.data?.telemetry).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters