From 48fd42357fe6814a4ea461ef7115de209e86d687 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Wed, 4 Sep 2024 09:08:45 -0700 Subject: [PATCH 1/3] Testing postbody --- scripts/aa-university.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/scripts/aa-university.js b/scripts/aa-university.js index 85488df..da3f7a7 100644 --- a/scripts/aa-university.js +++ b/scripts/aa-university.js @@ -3,16 +3,21 @@ 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}`)); } From 4b4e70c2da41700191c1f3f50961ac96941c02fc Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Thu, 5 Sep 2024 09:13:28 -0700 Subject: [PATCH 2/3] Adding the ability to have a group param added to the sandbox POST request. There is a default, so we do not want to send anything if we do not find the metadata --- scripts/aa-university.js | 4 +++- test/scripts/aa-university.test.js | 16 ++++++++++++++++ test/scripts/mocks/with-group.html | 8 ++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 test/scripts/mocks/with-group.html diff --git a/scripts/aa-university.js b/scripts/aa-university.js index da3f7a7..1706691 100644 --- a/scripts/aa-university.js +++ b/scripts/aa-university.js @@ -3,7 +3,7 @@ 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 group = document.querySelector('meta[name="sandboxgroup"]'); const postBody = { first_name: firstName?.value, @@ -20,4 +20,6 @@ export default function registerAAUniversity() { 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; + }); }); diff --git a/test/scripts/mocks/with-group.html b/test/scripts/mocks/with-group.html new file mode 100644 index 0000000..3ec0f17 --- /dev/null +++ b/test/scripts/mocks/with-group.html @@ -0,0 +1,8 @@ + +Jane +Doe +janedoe@email.com + From 014b4dd469b54bea1477e5542d19ef201b71db55 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Thu, 5 Sep 2024 09:20:28 -0700 Subject: [PATCH 3/3] Removing file not needed --- test/scripts/mocks/with-group.html | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 test/scripts/mocks/with-group.html diff --git a/test/scripts/mocks/with-group.html b/test/scripts/mocks/with-group.html deleted file mode 100644 index 3ec0f17..0000000 --- a/test/scripts/mocks/with-group.html +++ /dev/null @@ -1,8 +0,0 @@ - -Jane -Doe -janedoe@email.com -