Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new export flags #481

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/api/AmConfigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,20 @@ export async function getConfigEntity({

/**
* Get all other AM config entities
* @param {boolean} includeReadOnly Include read only config in the export
* @param {boolean} onlyRealm Get config only from the active realm. If onlyGlobal is also active, then it will also get the global config.
* @param {boolean} onlyGlobal Get global config only. If onlyRealm is also active, then it will also get the active realm config.
* @returns {Promise<ConfigSkeleton>} a promise that resolves to a config object containing global and realm config entities
*/
export async function getConfigEntities({
includeReadOnly = false,
onlyRealm = false,
onlyGlobal = false,
state,
}: {
includeReadOnly: boolean;
onlyRealm: boolean;
onlyGlobal: boolean;
state: State;
}): Promise<ConfigSkeleton> {
const realms = await getRealmsForExport({ state });
Expand All @@ -283,10 +292,14 @@ export async function getConfigEntities({
realm: Object.fromEntries(realms.map((r) => [r, {}])),
} as ConfigSkeleton;
for (const [key, entityInfo] of Object.entries(AM_ENTITIES)) {
if (!includeReadOnly && entityInfo.readonly) {
continue;
}
const deploymentAllowed =
entityInfo.deployments &&
entityInfo.deployments.includes(state.getDeploymentType());
if (
(onlyGlobal || !onlyRealm) &&
entityInfo.global &&
((entityInfo.global.deployments &&
entityInfo.global.deployments.includes(state.getDeploymentType())) ||
Expand Down Expand Up @@ -314,12 +327,21 @@ export async function getConfigEntities({
}
}
if (
(!onlyGlobal || onlyRealm) &&
entityInfo.realm &&
((entityInfo.realm.deployments &&
entityInfo.realm.deployments.includes(state.getDeploymentType())) ||
(entityInfo.realm.deployments == undefined && deploymentAllowed))
) {
const activeRealm = state.getRealm();
for (let i = 0; i < realms.length; i++) {
if (
onlyRealm &&
(activeRealm.startsWith('/') ? activeRealm : '/' + activeRealm) !==
stateRealms[i]
) {
continue;
}
try {
entities.realm[realms[i]][key] = await getConfigEntity({
state,
Expand Down
52 changes: 45 additions & 7 deletions src/ops/AmConfigOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,28 @@ describe('AmConfigOps', () => {
});

test('1: Export AM Config Entities', async () => {
// Set deployment type to cloud since it is necessary for exporting everything correctly. It does this automatically when recording the mock, but not when running the test after recording
state.setDeploymentType(Constants.CLOUD_DEPLOYMENT_TYPE_KEY);
const response = await AmConfigOps.exportAmConfigEntities({state});
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: false, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('2: Export importable AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: false, onlyRealm: false, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('3: Export alpha realm AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: true, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('4: Export global AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: false, onlyGlobal: true, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
Expand Down Expand Up @@ -129,10 +148,29 @@ describe('AmConfigOps', () => {
});

describe('exportAmConfigEntities()', () => {
test('2: Export AM Config Entities', async () => {
// Set deployment type to cloud since it is necessary for exporting everything correctly. It does this automatically when recording the mock, but not when running the test after recording
state.setDeploymentType(Constants.CLOUD_DEPLOYMENT_TYPE_KEY);
const response = await AmConfigOps.exportAmConfigEntities({state});
test('5: Export AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: false, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('6: Export importable AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: false, onlyRealm: false, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('7: Export root realm AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: true, onlyGlobal: false, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
});

test('8: Export global AM Config Entities', async () => {
const response = await AmConfigOps.exportAmConfigEntities({ includeReadOnly: true, onlyRealm: false, onlyGlobal: true, state });
expect(response).toMatchSnapshot({
meta: expect.any(Object),
});
Expand Down
38 changes: 34 additions & 4 deletions src/ops/AmConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ export type AmConfig = {
): Promise<ConfigEntityExportInterface>;
/**
* Export all other AM config entities
* @param {boolean} includeReadOnly Include read only config in the export
* @param {boolean} onlyRealm Export config only from the active realm. If onlyGlobal is also active, then it will also export the global config.
* @param {boolean} onlyGlobal Export global config only. If onlyRealm is also active, then it will also export the active realm config.
* @returns {Promise<ConfigEntityExportInterface>} promise resolving to a ConfigEntityExportInterface object
*/
exportAmConfigEntities(): Promise<ConfigEntityExportInterface>;
exportAmConfigEntities(
includeReadOnly: boolean,
onlyRealm: boolean,
onlyGlobal: boolean
): Promise<ConfigEntityExportInterface>;
/**
* Import all other AM config entities
* @param {ConfigEntityExportInterface} importData The config import data
Expand All @@ -47,8 +54,17 @@ export default (state: State): AmConfig => {
): Promise<ConfigEntityExportInterface> {
return createConfigEntityExportTemplate({ realms, state });
},
async exportAmConfigEntities(): Promise<ConfigEntityExportInterface> {
return exportAmConfigEntities({ state });
async exportAmConfigEntities(
includeReadOnly = false,
onlyRealm = false,
onlyGlobal = false
): Promise<ConfigEntityExportInterface> {
return exportAmConfigEntities({
includeReadOnly,
onlyRealm,
onlyGlobal,
state,
});
},
async importAmConfigEntities(
importData: ConfigEntityExportInterface
Expand Down Expand Up @@ -91,11 +107,20 @@ export async function createConfigEntityExportTemplate({

/**
* Export all other AM config entities
* @param {boolean} includeReadOnly Include read only config in the export
* @param {boolean} onlyRealm Export config only from the active realm. If onlyGlobal is also active, then it will also export the global config.
* @param {boolean} onlyGlobal Export global config only. If onlyRealm is also active, then it will also export the active realm config.
* @returns {Promise<ConfigEntityExportInterface>} promise resolving to a ConfigEntityExportInterface object
*/
export async function exportAmConfigEntities({
includeReadOnly = false,
onlyRealm = false,
onlyGlobal = false,
state,
}: {
includeReadOnly: boolean;
onlyRealm: boolean;
onlyGlobal: boolean;
state: State;
}): Promise<ConfigEntityExportInterface> {
let indicatorId: string;
Expand All @@ -104,7 +129,12 @@ export async function exportAmConfigEntities({
message: `AmConfigOps.exportAmConfigEntities: start`,
state,
});
const entities = await getConfigEntities({ state });
const entities = await getConfigEntities({
includeReadOnly,
onlyRealm,
onlyGlobal,
state,
});
const exportData = await createConfigEntityExportTemplate({
state,
realms: Object.keys(entities.realm),
Expand Down
132 changes: 126 additions & 6 deletions src/ops/ConfigOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ describe('ConfigOps', () => {
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
Expand All @@ -100,7 +103,64 @@ describe('ConfigOps', () => {
noDecode: true,
coords: false,
includeDefault: false,
includeActiveValues: false
includeActiveValues: false,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('3: Export only importable config with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: false,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('4: Export only alpha realm config with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: true,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('5: Export only global config with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: true,
}, state
});
expect(response).toMatchSnapshot({
Expand Down Expand Up @@ -129,29 +189,89 @@ describe('ConfigOps', () => {
setDefaultState(Constants.CLASSIC_DEPLOYMENT_TYPE_KEY);
});
describe('exportFullConfiguration()', () => {
test('3: Export everything with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
test('6: Export everything with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('4: Export everything without string arrays, decoding variables, excluding journey coordinates and default scripts', async () => {
test('7: Export everything without string arrays, decoding variables, excluding journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: false,
noDecode: true,
coords: false,
includeDefault: false,
includeActiveValues: false
includeActiveValues: false,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('8: Export only importable with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: false,
onlyRealm: false,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('9: Export only root realm config with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: true,
onlyGlobal: false,
}, state
});
expect(response).toMatchSnapshot({
meta: expect.any(Object)
});
});

test('10: Export only global config with string arrays, decoding variables, including journey coordinates and default scripts', async () => {
const response = await ConfigOps.exportFullConfiguration({
options: {
useStringArrays: true,
noDecode: false,
coords: true,
includeDefault: true,
includeActiveValues: true,
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: true,
}, state
});
expect(response).toMatchSnapshot({
Expand Down
Loading
Loading