Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Salesforce: second fix to UTF8 #589

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});
Loading