Skip to content
This repository has been archived by the owner on Sep 6, 2024. It is now read-only.

Commit

Permalink
Update NPM test (#5)
Browse files Browse the repository at this point in the history
* Add docker-compose mock test

* Update yarn.lock

* Add platform linux/amd64

* Update endpoint

* Remove mockserver and test via configurable connection

* Revert yarn.lock

* Update yarn.lock

* Add additional secrets to CI.yml

* Update CI.yml

* Update docker run command in CI.yml

* Revert test-linux-aarch64-gnu-binding docker run command

* Update CI.yml

* Remove quote around test-linux-aarch64-gnu-binding run options

* Add logs in test

* Update form of environment variables passed in CI.yml

* Remove test logs

* Update README.md
  • Loading branch information
paulkr authored May 10, 2024
1 parent 9fdd3a0 commit 87187a1
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 91 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INTEGRATIONOS_SECRET_KEY=
INTEGRATIONOS_CONNECTION_KEY=
INTEGRATIONOS_TESTING_MODEL=
17 changes: 14 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ jobs:
shell: bash
- name: Test bindings
run: yarn test
env:
INTEGRATIONOS_SECRET_KEY: ${{ secrets.INTEGRATIONOS_SECRET_KEY }}
INTEGRATIONOS_CONNECTION_KEY: ${{ secrets.INTEGRATIONOS_CONNECTION_KEY }}
INTEGRATIONOS_TESTING_MODEL: ${{ secrets.INTEGRATIONOS_TESTING_MODEL }}
test-linux-x64-gnu-binding:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
needs:
Expand Down Expand Up @@ -192,7 +196,11 @@ jobs:
run: ls -R .
shell: bash
- name: Test bindings
run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test
run: docker run --rm -v $(pwd):/build -w /build -e INTEGRATIONOS_SECRET_KEY=${{ env.INTEGRATIONOS_SECRET_KEY }} -e INTEGRATIONOS_CONNECTION_KEY=${{ env.INTEGRATIONOS_CONNECTION_KEY }} -e INTEGRATIONOS_TESTING_MODEL=${{ env.INTEGRATIONOS_TESTING_MODEL }} node:${{ matrix.node }}-slim yarn test
env:
INTEGRATIONOS_SECRET_KEY: ${{ secrets.INTEGRATIONOS_SECRET_KEY }}
INTEGRATIONOS_CONNECTION_KEY: ${{ secrets.INTEGRATIONOS_CONNECTION_KEY }}
INTEGRATIONOS_TESTING_MODEL: ${{ secrets.INTEGRATIONOS_TESTING_MODEL }}

test-linux-aarch64-gnu-binding:
name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }}
Expand Down Expand Up @@ -229,12 +237,15 @@ jobs:
uses: addnab/docker-run-action@v3
with:
image: node:${{ matrix.node }}-slim
options: "--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build"
options: --platform linux/arm64 -v ${{ github.workspace }}:/build -w /build -e INTEGRATIONOS_SECRET_KEY=${{ env.INTEGRATIONOS_SECRET_KEY }} -e INTEGRATIONOS_CONNECTION_KEY=${{ env.INTEGRATIONOS_CONNECTION_KEY }} -e INTEGRATIONOS_TESTING_MODEL=${{ env.INTEGRATIONOS_TESTING_MODEL }}
run: |
set -e
yarn test
ls -la
env:
INTEGRATIONOS_SECRET_KEY: ${{ secrets.INTEGRATIONOS_SECRET_KEY }}
INTEGRATIONOS_CONNECTION_KEY: ${{ secrets.INTEGRATIONOS_CONNECTION_KEY }}
INTEGRATIONOS_TESTING_MODEL: ${{ secrets.INTEGRATIONOS_TESTING_MODEL }}
publish:
name: Publish
runs-on: ubuntu-latest
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const response = await integrate
console.log(response);
```

## Testing

Configure the `.env` file based on the `.env.sample` provided with an IntegrationOS Secret Key, Connection Key and Model to test.

## Full Documentation

Please refer to the official IntegrationOS [Documentation](https://docs.integrationos.com/docs/setup) and [API Reference](https://docs.integrationos.com/reference) for more information and Node.js usage examples.
25 changes: 19 additions & 6 deletions __test__/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import('dotenv/config');
import test from 'ava'

import { IntegrationOS } from '../index.js'

test.before(t => {
const requiredEnvVars = [
'INTEGRATIONOS_SECRET_KEY',
'INTEGRATIONOS_CONNECTION_KEY',
'INTEGRATIONOS_TESTING_MODEL'
];

test('fetch customer', async (t) => {

const integrate = new IntegrationOS("sk_test_1_5wOEHNTqN8h6R7ErKHg_p9OPK1JE9AHPO3LrSUcmmIC-uZnKv1Z7ijPE2YrsURTS-830GyV_vQQhZeHG_Gc6Vd9A5SsJGg4Es5RqjjUoMQsDw8uWobpbCtBoAVsic08BFG6kf557lrytTGIo7563ikQfUqUfE2aO_ILg5tbYyZYZBMHd46GRTRwfa0_PhjhCFCpXnPE", {
serverUrl: "https://development-api.integrationos.com/v1/unified/"
requiredEnvVars.forEach(envVar => {
if (!process.env[envVar]) {
t.fail(`${envVar} is not set`);
}
});
});

test('List model entities', async (t) => {
const integrate = new IntegrationOS(process.env.INTEGRATIONOS_SECRET_KEY);

let response = await integrate.customers("test::shopify::andrew-test-0d1866cc98").list();
let response = await integrate[process.env.INTEGRATIONOS_TESTING_MODEL](process.env.INTEGRATIONOS_CONNECTION_KEY).list();

t.truthy(response.unified.length)
t.truthy(response.unified)
t.truthy(response.meta)
t.truthy(response.headers)
})
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn make_common_models(_item: TokenStream) -> TokenStream {
rt.block_on(async { get_common_models().await }).unwrap()
}

const ENDPOINT: &str = "https://development-api.integrationos.com/v1/public/e7262bf18c81bc1ff7f726e6d1a6da59f6e77dde0d63d9b60c041af57be8c197/";
const ENDPOINT: &str = "https://development-api.integrationos.com/v1/public/sdk/";
const LIMIT: u64 = 500;

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"postbuild": "sed -i'' -e 's/<Type>//g' index.js && sed -i'' -e '/^export type*/d' index.d.ts",
"prepublishOnly": "napi prepublish -t npm"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"dotenv": "^16.4.5"
}
}
6 changes: 1 addition & 5 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl IntegrationOS {
.as_ref()
.map(|o| {
let url = o.server_url.as_str();
if url.ends_with("/") {
&url[..url.len() - 1]
} else {
url
}
url.strip_suffix('/').unwrap_or(url)
})
.unwrap_or(DEFAULT_URL),
)
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/unified_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl UnifiedApi {
json!(status_code.as_u16()),
);

return Ok(serde_json::from_value(serde_json::Value::Object(map)).unwrap());
Ok(serde_json::from_value(serde_json::Value::Object(map)).unwrap())
}
_ => bail!("{{\"error\":\"Invalid response\"}}"),
}
Expand Down
Loading

0 comments on commit 87187a1

Please sign in to comment.