Skip to content

Commit

Permalink
Merge pull request #55 from lisb/feature/update-workflow-and-testscript
Browse files Browse the repository at this point in the history
Feature/update workflow and testscript
  • Loading branch information
krdlab authored Dec 9, 2022
2 parents 99b5d9c + b4cf977 commit a06b888
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
publish-npm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/

- run: npm publish
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ name: testing

on:
push:
paths:
- 'lib/**.js'
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 12, 14, 16 ]
node: [ 12, 14, 16, 18 ]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}

Expand Down
18 changes: 9 additions & 9 deletions test/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// 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 path = require("path");
const url = require("url");
const direct = require('../lib/direct-node.min.js').DirectAPI;
const fs = require('fs');
const path = require('path');
const url = require('url');

const endpoint = "wss://api.direct4b.com/albero-app-server/api";
const dotenv = path.join(process.cwd(), ".env");
const endpoint = 'wss://api.direct4b.com/albero-app-server/api';
const dotenv = path.join(process.cwd(), '.env');

const args = process.argv.slice(2);
if (args.length === 0 || !args[0].includes(':')) {
Expand All @@ -23,12 +23,12 @@ const client = direct.getInstance();
client.setOptions({
host: url.parse(endpoint).host,
endpoint: endpoint,
account
account,
});

client.on("access_token_changed", token => {
client.on('access_token_changed', (token) => {
fs.writeFileSync(dotenv, `HUBOT_DIRECT_TOKEN=${token}`);
console.log("logged in.");
console.log('logged in.');
process.exit();
});

Expand Down
73 changes: 57 additions & 16 deletions test/smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,76 @@
// 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 path = require("path");
const url = require("url");

const endpoint = "wss://api.direct4b.com/albero-app-server/api";
const dotenv = path.join(process.cwd(), ".env");
const accessToken = fs
.readFileSync(dotenv)
.toString()
.replace("HUBOT_DIRECT_TOKEN=", "");
const direct = require('../lib/direct-node.min.js').DirectAPI;
const fs = require('fs');
const path = require('path');
const url = require('url');

const endpoint = 'wss://api.direct4b.com/albero-app-server/api';
const dotenv = path.join(process.cwd(), '.env');
const accessToken = fs.readFileSync(dotenv).toString().replace('HUBOT_DIRECT_TOKEN=', '');

const client = direct.getInstance();

client.setOptions({
host: url.parse(endpoint).host,
endpoint: endpoint,
access_token: accessToken
access_token: accessToken,
});

client.on("data_recovered", () => {
console.log("Good");
process.exit();
client.on('data_recovered', () => {
console.info('data recovered');
if (
validUserObject(Object.values(client.userObjects())[0]) &&
validTalkObject(Object.values(client.talkObjects())[0]) &&
validDomainObject(Object.values(client.domainObjects())[0])
) {
console.info('Good');
process.exit();
} else {
process.exit(1);
}
});

client.on("error_occurred", (err, data) => {
client.on('error_occurred', (err, data) => {
console.error(`Bad: ${err}`);
console.log(data);
process.exit(1);
});

client.listen();

function validUserObject(u) {
return (
u.id != null &&
u.id_i64 != null &&
u.name != null &&
u.displayName != null &&
u.updatedAt != null
);
}

function validTalkObject(t) {
return (
t.id != null &&
t.id_i64 != null &&
t.type != null &&
t.users != null &&
t.userIds != null &&
t.domain != null &&
t.domainId != null &&
t.domainId_i64 != null
);
}

function validDomainObject(d) {
return (
d.id != null &&
d.id_i64 != null &&
d.domainInfo != null &&
d.profileDefinition != null &&
d.setting != null &&
d.role != null &&
d.updatedAt != null
);
}

0 comments on commit a06b888

Please sign in to comment.