diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml new file mode 100644 index 0000000..75f9791 --- /dev/null +++ b/.github/workflows/npmpublish.yml @@ -0,0 +1,18 @@ +name: Node.js Package + +on: + release: + types: [created] + +jobs: + publish-npm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12 + registry-url: https://registry.npmjs.org/ + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..eff7a41 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,29 @@ +name: testing + +on: + push: + paths: + - 'lib/**.js' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 12.x + - run: npm install + + - name: Run smoke tests + timeout-minutes: 2 + run: | + touch .credential + echo ${{ secrets.DIRECT_TESTING_USER }} >> .credential + echo ${{ secrets.DIRECT_TESTING_PASSWORD }} >> .credential + node test/login.js < .credential + node test/smoke.js + + - name: Remove credentials + run: rm -f .credential .env diff --git a/.npmignore b/.npmignore index 96d484f..bd9bb2a 100644 --- a/.npmignore +++ b/.npmignore @@ -7,4 +7,6 @@ lib/*.map lib/sample.* lib/example.* example/ +test/ +.github/ bower.json diff --git a/test/login.js b/test/login.js new file mode 100644 index 0000000..a7cd181 --- /dev/null +++ b/test/login.js @@ -0,0 +1,25 @@ +// Copyright (c) 2020 L is B Corp. +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +const direct = require("../lib/direct-node.min.js").DirectAPI; +const fs = require("fs"); +const url = require("url"); + +const endpoint = "wss://api.direct4b.com/albero-app-server/api"; + +const client = direct.getInstance(); + +client.setOptions({ + host: url.parse(endpoint).host, + endpoint: endpoint +}); + +client.on("access_token_changed", token => { + fs.writeFileSync(".env", `HUBOT_DIRECT_TOKEN=${token}`); + console.log("logged in."); + process.exit(); +}); + +client.listen(); diff --git a/test/smoke.js b/test/smoke.js new file mode 100644 index 0000000..d035e63 --- /dev/null +++ b/test/smoke.js @@ -0,0 +1,35 @@ +// Copyright (c) 2020 L is B Corp. +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +const direct = require("../lib/direct-node.min.js").DirectAPI; +const fs = require("fs"); +const url = require("url"); + +const endpoint = "wss://api.direct4b.com/albero-app-server/api"; +const accessToken = fs + .readFileSync(".env") + .toString() + .replace("HUBOT_DIRECT_TOKEN=", ""); + +const client = direct.getInstance(); + +client.setOptions({ + host: url.parse(endpoint).host, + endpoint: endpoint, + access_token: accessToken +}); + +client.on("data_recovered", () => { + console.log("Good"); + process.exit(); +}); + +client.on("error_occurred", (err, data) => { + console.error(`Bad: ${err}`); + console.log(data); + process.exit(1); +}); + +client.listen();