Update the getKcContext function
This commit is contained in:
parent
9bbfac0896
commit
87ed9884ff
@ -86,25 +86,17 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|||||||
"source": partialKcContextCustomMock
|
"source": partialKcContextCustomMock
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
if ("profile" in partialKcContextCustomMock) {
|
||||||
partialKcContextCustomMock.pageId === "register-user-profile.ftl" ||
|
assert(kcContextDefaultMock !== undefined && "profile" in kcContextDefaultMock);
|
||||||
partialKcContextCustomMock.pageId === "update-user-profile.ftl" ||
|
|
||||||
partialKcContextCustomMock.pageId === "idp-review-user-profile.ftl"
|
|
||||||
) {
|
|
||||||
assert(
|
|
||||||
kcContextDefaultMock?.pageId === "register-user-profile.ftl" ||
|
|
||||||
kcContextDefaultMock?.pageId === "update-user-profile.ftl" ||
|
|
||||||
kcContextDefaultMock?.pageId === "idp-review-user-profile.ftl"
|
|
||||||
);
|
|
||||||
|
|
||||||
const { attributes } = kcContextDefaultMock.profile;
|
const { attributes } = kcContextDefaultMock.profile;
|
||||||
|
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes = [];
|
id<KcContext.Register>(kcContext).profile.attributes = [];
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName = {};
|
id<KcContext.Register>(kcContext).profile.attributesByName = {};
|
||||||
|
|
||||||
const partialAttributes = [
|
const partialAttributes = [...((partialKcContextCustomMock as DeepPartial<KcContext.Register>).profile?.attributes ?? [])].filter(
|
||||||
...((partialKcContextCustomMock as DeepPartial<KcContext.RegisterUserProfile>).profile?.attributes ?? [])
|
exclude(undefined)
|
||||||
].filter(exclude(undefined));
|
);
|
||||||
|
|
||||||
attributes.forEach(attribute => {
|
attributes.forEach(attribute => {
|
||||||
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
const partialAttribute = partialAttributes.find(({ name }) => name === attribute.name);
|
||||||
@ -125,8 +117,8 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(augmentedAttribute);
|
id<KcContext.Register>(kcContext).profile.attributes.push(augmentedAttribute);
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
id<KcContext.Register>(kcContext).profile.attributesByName[augmentedAttribute.name] = augmentedAttribute;
|
||||||
});
|
});
|
||||||
|
|
||||||
partialAttributes
|
partialAttributes
|
||||||
@ -136,8 +128,8 @@ export function createGetKcContext<KcContextExtension extends { pageId: string }
|
|||||||
|
|
||||||
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
assert(name !== undefined, "If you define a mock attribute it must have at least a name");
|
||||||
|
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributes.push(partialAttribute as any);
|
id<KcContext.Register>(kcContext).profile.attributes.push(partialAttribute as any);
|
||||||
id<KcContext.RegisterUserProfile>(kcContext).profile.attributesByName[name] = partialAttribute as any;
|
id<KcContext.Register>(kcContext).profile.attributesByName[name] = partialAttribute as any;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user