Skip to content

Instantly share code, notes, and snippets.

@Aaronius
Created January 26, 2021 23:23
Show Gist options
  • Save Aaronius/5cbadeee49b6e941b043183186a299ad to your computer and use it in GitHub Desktop.
Save Aaronius/5cbadeee49b6e941b043183186a299ad to your computer and use it in GitHub Desktop.
Setting up launch properties and edge configurations for Debugger e2e tests
async function setUpEdgeConfigurationAndEnvironment({ blackbird }) {
console.log('Creating edge configuration.');
const config = await blackbird.createConfig({
description: 'Dummy from test',
enabled: true,
title: `Debugger E2E Test Config ${uuid()}`,
type: ''
});
const environment = await blackbird.createEnvironment(config.id, {
type: 'development',
title: 'Development Environment',
name: 'dev',
description: '',
settings: {
com_adobe_audiencemanager: {
enabled: false,
storedDestinationsEnabled: true,
urlDestinationsEnabled: true
},
com_adobe_experience_platform: { enabled: false },
com_adobe_target: { enabled: false },
com_adobe_analytics: { enabled: false, reportSuites: [] },
com_adobe_launch_ssf: { enabled: true, propertyId: 'PR123', environmentId: 'EN123' }
}
});
console.log('Created edge configuration.', environment);
return environment.compositeId;
}
async function setUpLaunchEdgeProperty({ reactor }) {
const property = await createProperty({
reactor,
companyId: secrets.launchCompanyId,
platform: 'edge'
});
const host = await createHost({ reactor, propertyId: property.id, type: 'cloudflare_worker' });
const environment = await createEnvironment({
reactor,
propertyId: property.id,
hostId: host.id
});
console.log('Installing Adobe Cloud Connector extension.');
const extensionPackagesResponse = await reactor.listExtensionPackages({
'filter[platform]': 'EQ edge',
'filter[name]': 'EQ adobe-cloud-connector'
});
const cloudConnectorExtensionPackage = extensionPackagesResponse.data[0];
if (!cloudConnectorExtensionPackage) {
throw new Error('Adobe Cloud Connector extension package not found.');
}
const extensionResponse = await reactor.createExtension(property.id, {
attributes: {},
relationships: {
extension_package: {
data: {
id: cloudConnectorExtensionPackage.id,
type: 'extension_packages'
}
}
},
type: 'extensions'
});
const cloudConnectorExtension = extensionResponse.data;
console.log('Installed Adobe Cloud Connector extension.');
console.log('Creating data element.');
const extensionsResponse = await reactor.listExtensionsForProperty(property.id, {
'filter[platform]': 'EQ edge',
'filter[name]': 'EQ core'
});
const coreExtension = extensionsResponse.data[0];
if (!coreExtension) {
throw new Error('Core extension not found.');
}
const dataElementResponse = await reactor.createDataElement(property.id, {
attributes: {
delegate_descriptor_id: 'core::dataElements::path',
name: 'request',
settings: '{"path":"arc.request"}'
},
relationships: {
extension: {
data: {
id: coreExtension.id,
type: 'extensions'
}
}
},
type: 'data_elements'
});
const dataElement = dataElementResponse.data;
console.log('Created data element.');
const rule = await createRule({ reactor, propertyId: property.id });
console.log('Creating Send Data action.');
await reactor.createRuleComponent(property.id, {
attributes: {
delegate_descriptor_id: 'adobe-cloud-connector::actions::send-data',
name: 'Adobe Cloud Connector - Send Data',
settings: `{"method":"POST","url":"${secrets.webhookSiteEndpoint +
secrets.webhookSiteToken}","body":"{{request}}"}`
},
relationships: {
extension: {
data: {
id: cloudConnectorExtension.id,
type: 'extensions'
}
},
rules: {
data: [
{
id: rule.id,
type: 'rules'
}
]
}
},
type: 'rule_components'
});
console.log('Created Send Data action.');
console.log('Creating library.');
const libraryResponse = await reactor.createLibrary(property.id, {
attributes: {
name: `Debugger E2E Test Run Library ${uuid()}`
},
relationships: {
data_elements: {
data: [
{
id: dataElement.id,
meta: {
action: 'revise'
},
type: 'data_elements'
}
]
},
environment: {
data: {
id: environment.id,
type: 'environments'
}
},
extensions: {
data: [
{
id: cloudConnectorExtension.id,
meta: {
action: 'revise'
},
type: 'extensions'
},
{
id: coreExtension.id,
meta: {
action: 'revise'
},
type: 'extensions'
}
]
},
rules: {
data: [
{
id: rule.id,
meta: {
action: 'revise'
},
type: 'rules'
}
]
}
},
type: 'libraries'
});
const library = libraryResponse.data;
console.log('Created library.');
await startAndWaitForBuild({ reactor, libraryId: library.id });
console.log('Launch edge property has been set up.');
}
async function setUpLaunchWebProperty({ reactor, edgeConfigId, onEmbedCodeCreated }) {
const property = await createProperty({
reactor,
companyId: secrets.launchCompanyId,
platform: 'web'
});
const host = await createHost({ reactor, propertyId: property.id, type: 'akamai' });
const environment = await createEnvironment({
reactor,
propertyId: property.id,
hostId: host.id
});
const embedCode = `<script src="${environment.attributes.path}/${environment.attributes.library_path}/${environment.attributes.library_name}" async></script>`;
console.log('Installing AEP Web SDK extension.');
const extensionPackagesResponse = await reactor.listExtensionPackages({
'filter[platform]': 'EQ web',
'filter[name]': 'EQ adobe-alloy'
});
const alloyExtensionPackage = extensionPackagesResponse.data[0];
if (!alloyExtensionPackage) {
throw new Error('AEP Web SDK extension package not found.');
}
const extensionResponse = await reactor.createExtension(property.id, {
attributes: {
delegate_descriptor_id: 'adobe-alloy::extensionConfiguration::config',
settings: `{"instances":[{"name":"alloy","edgeConfigId":"${edgeConfigId}","stagingEdgeConfigId":"${edgeConfigId}","developmentEdgeConfigId":"${edgeConfigId}"}]}`
},
relationships: {
extension_package: {
data: {
id: alloyExtensionPackage.id,
type: 'extension_packages'
}
}
},
type: 'extensions'
});
console.log(extensionResponse);
const alloyExtension = extensionResponse.data;
console.log('Installed AEP Web SDK extension.');
const rule = await createRule({ reactor, propertyId: property.id });
console.log('Creating CLick event.');
const extensionsResponse = await reactor.listExtensionsForProperty(property.id, {
'filter[platform]': 'EQ web',
'filter[name]': 'EQ core'
});
const coreExtension = extensionsResponse.data[0];
if (!coreExtension) {
throw new Error('Core extension not found.');
}
await reactor.createRuleComponent(property.id, {
attributes: {
delegate_descriptor_id: 'core::events::click',
name: 'Core - Click',
settings: '{}'
},
relationships: {
extension: {
data: {
id: coreExtension.id,
type: 'extensions'
}
},
rules: {
data: [
{
id: rule.id,
type: 'rules'
}
]
}
},
type: 'rule_components'
});
console.log('Created Click event.');
console.log('Creating Send Event action.');
await reactor.createRuleComponent(property.id, {
attributes: {
delegate_descriptor_id: 'adobe-alloy::actions::send-event',
name: 'AEP Web SDK - Send Event',
settings: '{"instanceName":"alloy"}'
},
relationships: {
extension: {
data: {
id: alloyExtension.id,
type: 'extensions'
}
},
rules: {
data: [
{
id: rule.id,
type: 'rules'
}
]
}
},
type: 'rule_components'
});
console.log('Created Send Event action.');
console.log('Creating library.');
const libraryResponse = await reactor.createLibrary(property.id, {
attributes: {
name: `Debugger E2E Test Run Library ${uuid()}`
},
relationships: {
environment: {
data: {
id: environment.id,
type: 'environments'
}
},
extensions: {
data: [
{
id: alloyExtension.id,
meta: {
action: 'revise'
},
type: 'extensions'
},
{
id: coreExtension.id,
meta: {
action: 'revise'
},
type: 'extensions'
}
]
},
rules: {
data: [
{
id: rule.id,
meta: {
action: 'revise'
},
type: 'rules'
}
]
}
},
type: 'libraries'
});
const library = libraryResponse.data;
console.log('Created library.');
await startAndWaitForBuild({ reactor, libraryId: library.id });
console.log('Launch web property has been set up.');
return embedCode;
}
async function startAndWaitForBuild({ reactor, libraryId }) {
console.log('Starting build.');
const buildResponse = await reactor.createBuild(libraryId);
const build = buildResponse.data;
const hasBuildSucceeded = async () => {
console.log('Checking if build has succeeded.');
const buildCheckResponse = await reactor.getBuild(build.id);
const buildSucceeded = buildCheckResponse.data.attributes.status === 'succeeded';
console.log(`Build has ${buildSucceeded ? '' : 'not yet '}succeeded.`);
return buildSucceeded;
};
await pWaitFor(hasBuildSucceeded, {
interval: 500,
timeout: 30000
});
}
async function createProperty({ reactor, companyId, platform }) {
console.log('Creating property.');
const attributes = {
platform,
name: `Debugger E2E Test Run ${uuid()}`
};
if (platform === 'web') {
attributes.domains = ['example.com'];
}
const propertyResponse = await reactor.createProperty(companyId, {
attributes,
type: 'properties'
});
const property = propertyResponse.data;
console.log('Created property.');
return property;
}
async function createHost({ reactor, propertyId, type }) {
console.log('Creating host.');
const hostResponse = await reactor.createHost(propertyId, {
attributes: {
name: 'Managed by Adobe',
type_of: type
},
type: 'hosts'
});
const host = hostResponse.data;
console.log('Created host.');
return host;
}
async function createEnvironment({ reactor, propertyId, hostId }) {
console.log('Creating environment.');
const environmentResponse = await reactor.createEnvironment(propertyId, {
attributes: {
name: 'Development',
stage: 'development'
},
relationships: {
host: {
data: {
id: hostId,
type: 'hosts'
}
}
},
type: 'environments'
});
const environment = environmentResponse.data;
console.log('Created environment.');
return environment;
}
async function createRule({ reactor, propertyId }) {
console.log('Creating rule.');
const ruleResponse = await reactor.createRule(propertyId, {
attributes: {
name: `Debugger E2E Test Run Rule ${uuid()}`
},
type: 'rules'
});
const rule = ruleResponse.data;
console.log('Created rule.');
return rule;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment