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

Fix console S/MMS compose #38

Merged
merged 1 commit into from
Sep 1, 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
10 changes: 4 additions & 6 deletions bin/txms
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function parseArgs(argv) {
break;
case '--getendpoint':
args.kind = 'getendpoint';
args.value = value; // Network type for getEndpoint
args.value = value || 1; // Network type for getEndpoint
break;
case '--sms':
args.kind = 'sms';
Expand Down Expand Up @@ -89,7 +89,7 @@ function parseArgs(argv) {
break;
case '-g':
args.kind = 'getendpoint';
args.value = value;
args.value = value || 1;
break;
case '-s':
args.kind = 'sms';
Expand Down Expand Up @@ -239,13 +239,11 @@ async function run(kind, value, output, countryCodes, phoneNumbers, download, fi
process.stdout.write(endpointString + newline);
process.exit(0);
} else if (kind === 'sms') {
const message = txms.encode(value);
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, message);
const sms = txms.sms(phoneNumbers ? phoneNumbers.split(',') : true, value);
process.stdout.write(sms + newline);
process.exit(0);
} else if (kind === 'mms') {
const message = txms.encode(value);
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, message);
const mms = txms.mms(phoneNumbers ? phoneNumbers.split(',') : true, value);
process.stdout.write(mms + newline);
process.exit(0);
} else {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "txms.js",
"version": "1.3.0",
"version": "1.3.1",
"description": "Transaction messaging service protocol",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -46,7 +46,7 @@
"author": "@bchainhub",
"license": "CORE",
"devDependencies": {
"@types/node": "^22.5.1",
"@types/node": "^22.5.2",
"@typescript-eslint/eslint-plugin": "^8.3.0",
"@typescript-eslint/parser": "^8.3.0",
"eslint": "^9.9.1",
Expand Down
10 changes: 10 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,16 @@ describe('CLI Tests', () => {
assert.strictEqual(parseInt(result.stdout.toString(), 10), samples.valid[0].length);
});

test('Should compose SMS link with piping', () => {
const hexValue = samples.valid[0].hex;
const echo = spawnSync('echo', [hexValue]);
const result = spawnSync('node', [txmsPath, '--encode', '-s'], {
input: echo.stdout
});
assert.strictEqual(result.status, 0);
assert.match(result.stdout.toString(), /^sms:\+12019715152\?body=/);
});

test('Should print help text', () => {
const result = spawnSync('node', [txmsPath, '--help']);
assert.strictEqual(result.status, 0);
Expand Down