Skip to content

Commit

Permalink
Merge pull request #589 from OpenFn/fix-salesforce-any-ascii-again
Browse files Browse the repository at this point in the history
Salesforce: second fix to UTF8
  • Loading branch information
josephjclark authored May 28, 2024
2 parents d1b5fe4 + f67c514 commit 1335557
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
6 changes: 6 additions & 0 deletions packages/salesforce/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @openfn/language-salesforce

## 4.6.9

### Patch Changes

- Fix any-ascii load and add more tests

## 4.6.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/salesforce/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/language-salesforce",
"version": "4.6.8",
"version": "4.6.9",
"description": "Salesforce Language Pack for OpenFn",
"homepage": "https://docs.openfn.org",
"exports": {
Expand Down
12 changes: 9 additions & 3 deletions packages/salesforce/src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ let anyAscii = undefined;

// use a dynamic import because any-ascii is pure ESM and doesn't play well with CJS
// This promise MUST be resolved by execute before a connection is created
const loadAnyAscii = import('any-ascii').then(m => {
anyAscii = m.default;
});
const loadAnyAscii = state =>
import('any-ascii').then(m => {
anyAscii = m.default;
return state;
});

/**
* Adds a lookup relation or 'dome insert' to a record.
Expand Down Expand Up @@ -764,6 +766,10 @@ function createAccessTokenConnection(state) {
* @returns {State}
*/
function createConnection(state) {
if (state.connection) {
return state;
}

const { access_token } = state.configuration;

return access_token
Expand Down
37 changes: 22 additions & 15 deletions packages/salesforce/test/Adaptor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ import {
upsert,
upsertIf,
toUTF8,
steps,
each,
field,
fields,
sourceValue,
execute,
} from '../src/Adaptor';

import testData from './testData' assert { type: 'json' };

const { expect } = chai;

describe('Adaptor', () => {
Expand Down Expand Up @@ -173,18 +166,32 @@ describe('Adaptor', () => {
});

describe('toUTF8', () => {
it('Transliterate unicode to ASCII representation', () => {
expect(toUTF8('άνθρωποι')).to.eql('anthropoi');
it('Transliterate unicode to ASCII representation', async () => {
const state = {
connection: {},
};

// Run toUTF8 inside an execute block to ensure that any-ascii gets loaded correctly
const convert = str => execute(state => toUTF8(str))(state);

let result = await convert('άνθρωποι');
expect(result).to.eql('anthropoi');

// Misc
expect(toUTF8('☆ ♯ ♰ ⚄ ⛌')).to.equal('* # + 5 X');
result = await convert('☆ ♯ ♰ ⚄ ⛌');
expect(result).to.equal('* # + 5 X');

// Emojis
expect(toUTF8('👑 🌴')).to.eql(':crown: :palm_tree:');
result = await convert('👑 🌴');
expect(result).to.eql(':crown: :palm_tree:');

// Letterlike
expect(toUTF8('№ ℳ ⅋ ⅍')).to.eql('No M & A/S');
result = await convert('№ ℳ ⅋ ⅍');
expect(result).to.eql('No M & A/S');

// Ordinal coordinator
expect(toUTF8('Nhamaonha 6ª Classe 2023-10-09')).to.eql(
'Nhamaonha 6a Classe 2023-10-09'
);
result = await convert('Nhamaonha 6ª Classe 2023-10-09');
expect(result).to.eql('Nhamaonha 6a Classe 2023-10-09');
});
});
});

0 comments on commit 1335557

Please sign in to comment.