diff --git a/head.html b/head.html index e1fb9ec..89f84b8 100644 --- a/head.html +++ b/head.html @@ -1,4 +1,32 @@ + + diff --git a/scripts/aa-university.js b/scripts/aa-university.js index 85488df..1706691 100644 --- a/scripts/aa-university.js +++ b/scripts/aa-university.js @@ -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; } diff --git a/test/scripts/aa-university.test.js b/test/scripts/aa-university.test.js index 976ab04..272d82e 100644 --- a/test/scripts/aa-university.test.js +++ b/test/scripts/aa-university.test.js @@ -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; + }); });