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

[Release] Stage to Main #241

Merged
merged 14 commits into from
Sep 10, 2024
Merged
28 changes: 28 additions & 0 deletions head.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="preload" href="/styles/styles.css" as="style"/>
<script>
const libs = (() => {
const { hostname, search } = window.location;
if (!['.hlx.', '.stage.', 'local'].some((i) => hostname.includes(i))) return '/libs';
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
})();

const miloStyles = document.createElement('link');
const miloUtils = document.createElement('link');
const miloDecorate = document.createElement('link');

miloStyles.setAttribute('as', 'style');
miloStyles.setAttribute('href', `${libs}/styles/styles.css`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

[miloUtils, miloDecorate].forEach((tag) => {
tag.setAttribute('crossorigin', 'true');
tag.setAttribute('as', 'script');
})

miloUtils.setAttribute('href', `${libs}/utils/utils.js`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.
miloDecorate.setAttribute('href', `${libs}/utils/decorate.js`);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

[miloStyles, miloUtils, miloDecorate].forEach((tag) => tag.setAttribute('rel', 'preload'));
document.head.append(miloStyles, miloUtils, miloDecorate);
</script>
<script src="/scripts/scripts.js" type="module"></script>
<style>body { display: none; }</style>
<link rel="icon" href="data:,">
21 changes: 14 additions & 7 deletions scripts/aa-university.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ export default function registerAAUniversity() {
const lastName = document.querySelector('input[name="LastName"]');
const email = document.querySelector('input[name="Email"]');
const country = document.querySelector('select[name="Country"]');
const group = document.querySelector('meta[name="sandboxgroup"]');

const postBody = {
first_name: firstName?.value,
last_name: lastName?.value,
email: email?.value,
university: 'none',
country: country?.value,
};

if (group) postBody.group = group.content;

fetch('https://us-central1-adobe---aa-university.cloudfunctions.net/register', {
method: 'POST',
body: JSON.stringify({
first_name: firstName?.value,
last_name: lastName?.value,
email: email?.value,
university: 'none',
country: country?.value,
}),
body: JSON.stringify(postBody),
})
.catch((error) => window.lana.log(`Marketo AA University Error: ${error}`));

return postBody;
}
16 changes: 16 additions & 0 deletions test/scripts/aa-university.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,20 @@ describe('AA University', async () => {
window.fetch = ogFetch;
window.lana = ogLana;
});

it('Sends the group parameter with POST if found', () => {
const meta = document.createElement('meta');
meta.setAttribute('name', 'sandboxgroup');
meta.setAttribute('content', 'group');
document.body.prepend(meta);
const body = registerAAUniversity();
expect(body.group).to.equal('group');

document.querySelector('meta').remove();
});

it('Does not send the group parameter with POST if not found', () => {
const body = registerAAUniversity();
expect(body.group).to.be.undefined;
});
});
Loading