-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* universal promo terms 1st commit * Added API failure case handler * Remove console.log and updated the failure case. * nit: typo * Setting default api_key * nit: TODO * icon / other original content support, css to hide header/footer completely. * poc reviewd * api key updated * nit: eslint update * nit: eslint update * nit: eslint update * nit: eslint update * nit: eslint update * nit: eslint update * test added * added test * MWPW-142280 Firefly single feature marquee (#191) * firefly single feature * fix lint issue * fix blinking cursor issue on mobile and tablet * optimize --------- Co-authored-by: Ruchika Sinha <tek10248@Ruchikas-MacBook-Pro.local> * MWPW-143215 [sidenav] make re-ordering possible with camel case (#192) * service_providers is now optional as api_key * update test * MWPW-143533-Handle css for 2 values in selector tray (#195) * MWPW-143533 * fix issues --------- Co-authored-by: Ruchika Sinha <tek10248@Ruchikas-MacBook-Pro.local> * [Universal promo terms] update env logic (#197) * stage condition added for env * check prod URL instead --------- Co-authored-by: Sean Choi <seanchoi@adobe.com> Co-authored-by: Ruchika Sinha <tek10248@Ruchikas-MacBook-Pro.local> Co-authored-by: Nicolas Peltier <1032754+npeltier@users.noreply.github.com>
- Loading branch information
1 parent
ee2a98d
commit f57f7c6
Showing
12 changed files
with
297 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
creativecloud/blocks/universal-promo-terms/universal-promo-terms.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@media (min-width: 900px) { | ||
body .feds-topnav-wrapper { | ||
border: 0; | ||
} | ||
} | ||
|
||
body .global-footer { | ||
background: none; | ||
} |
52 changes: 52 additions & 0 deletions
52
creativecloud/blocks/universal-promo-terms/universal-promo-terms.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const OFFER_ID_API_BASE = 'https://aos.adobe.io/offers/'; | ||
const SELECTOR_ID_API_BASE = 'https://aos.adobe.io/offers:search.selector'; | ||
const STAGE_OFFER_ID_API_BASE = 'https://aos-stage.adobe.io/offers/'; | ||
const STAGE_SELECTOR_ID_API_BASE = 'https://aos-stage.adobe.io/offers:search.selector'; | ||
const API_KEY = 'universalPromoTerm'; | ||
const SERVICE_PROVIDERS = 'PROMO_TERMS'; | ||
|
||
function getEnv(env) { | ||
if (env) return env; | ||
if (window.location.origin.hostname === 'www.adobe.com') return 'production'; | ||
return 'stage'; | ||
} | ||
|
||
async function getTermsHTML(params, el, env, search) { | ||
const locationSearch = search ?? window.location.search; | ||
let promoTerms; | ||
if (!params.get('offer_selector_ids')) { | ||
let fetchURL = `${env === 'stage' ? STAGE_OFFER_ID_API_BASE : OFFER_ID_API_BASE}${params.get('offer_id')}${locationSearch}`; | ||
fetchURL += params.get('api_key') ? '' : `&api_key=${API_KEY}`; | ||
fetchURL += params.get('service_providers') ? '' : `&service_providers=${SERVICE_PROVIDERS}`; | ||
|
||
const res = await fetch(fetchURL); | ||
if (!res.ok) return false; | ||
const json = await res.json(); | ||
promoTerms = json[0]?.promo_terms; | ||
} else { | ||
let fetchURL = `${env === 'stage' ? STAGE_SELECTOR_ID_API_BASE : SELECTOR_ID_API_BASE}${locationSearch}`; | ||
fetchURL += params.get('api_key') ? '' : `&api_key=${API_KEY}`; | ||
fetchURL += params.get('service_providers') ? '' : `&service_providers=${SERVICE_PROVIDERS}`; | ||
|
||
const res = await fetch(fetchURL); | ||
if (!res.ok) return false; | ||
const json = await res.json(); | ||
promoTerms = json[0]?.offers[0]?.promo_terms; | ||
} | ||
|
||
if (!promoTerms || !promoTerms.header || !promoTerms.text) { | ||
return false; | ||
} | ||
return `<div class="container">${el.innerHTML}<h1>${promoTerms.header}</h1><p>${promoTerms.text}</p></div>`; | ||
} | ||
|
||
export default async function init(el, search) { | ||
const params = new URLSearchParams(search ?? window.location.search); | ||
const env = getEnv(params.get('env')); | ||
const termsHTML = await getTermsHTML(params, el, env, search); | ||
if (!termsHTML && env !== 'stage') { | ||
window.location = '404.html'; | ||
} else { | ||
el.innerHTML = termsHTML; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div> | ||
<div class="universal-promo-terms"></div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
test/blocks/universal-promo-terms/universal.promo.terms.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { readFile } from '@web/test-runner-commands'; | ||
import { expect } from '@esm-bundle/chai'; | ||
import sinon from 'sinon'; | ||
|
||
document.body.innerHTML = await readFile({ path: './mocks/body.html' }); | ||
const { default: init } = await import('../../../creativecloud/blocks/universal-promo-terms/universal-promo-terms.js'); | ||
|
||
describe('universal-promo-terms', () => { | ||
const block = document.body.querySelector('.universal-promo-terms'); | ||
beforeEach(() => { | ||
sinon.spy(console, 'log'); | ||
}); | ||
|
||
afterEach(() => { | ||
console.log.restore(); | ||
}); | ||
|
||
it('Get API from query parameters', async () => { | ||
await init(block, '?offer_id=1B365A793986BBEEE26F3E372BDAAB09&locale=de_DE&promotion_code=fixed_dis_20&country=DE&env=stage'); | ||
expect(document.querySelector('.universal-promo-terms').textContent).to.not.equal('false'); | ||
}); | ||
}); |
Oops, something went wrong.