Skip to content

Instantly share code, notes, and snippets.

@wiserfirst
Created April 19, 2021 05:06
Show Gist options
  • Save wiserfirst/701d319ea4def830058166b19df57eaf to your computer and use it in GitHub Desktop.
Save wiserfirst/701d319ea4def830058166b19df57eaf to your computer and use it in GitHub Desktop.
const encode64 = str => Buffer.from(str).toString('base64')
describe('base64 encoding comparison', () => {
const triggerId = 'direct1'
const fulfilmentType = 'ClickandCollect'
const orderId = '000000123'
const string = `{"property-value-westfield_direct_trigger_id":["${triggerId}"],"property-value-westfield_direct_received_fulfilment_type":["${fulfilmentType}"],"property-value-westfield_direct_received_order_id":["${orderId}"]}`
it('should produce same result', () => {
const encoded = encode64(string)
const result =
encode64('{"property-value-westfield_direct_trigger_id":["') +
encode64(triggerId) +
encode64(
'"],"property-value-westfield_direct_received_fulfilment_type":["'
) +
encode64(fulfilmentType) +
encode64('"],"property-value-westfield_direct_received_order_id":["') +
encode64(orderId) +
encode64('"]}')
expect(result).toEqual(encoded)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment