Skip to content

Commit

Permalink
abstract and add test for chart alias display
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbosworth committed Oct 26, 2020
1 parent 3e40446 commit 3a173fe
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
29 changes: 29 additions & 0 deletions display/chart_alias_for_peer.js

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

42 changes: 42 additions & 0 deletions test/display/test_chart_alias_for_peer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const {test} = require('tap');

const {chartAliasForPeer} = require('./../../display');

const tests = [
{
args: {
alias: 'alias',
public_key: Buffer.alloc(33).toString('hex'),
},
description: 'A chart alias is returned',
expected: {display: 'alias'},
},
{
args: {
alias: '',
public_key: Buffer.alloc(33).toString('hex'),
},
description: 'A chart alias with short key is returned',
expected: {display: Buffer.alloc(8).toString('hex')},
},
{
args: {
alias: '',
is_disconnected: true,
is_inactive: true,
public_key: Buffer.alloc(33).toString('hex'),
},
description: 'A chart alias with emojis is returned',
expected: {display: '🚪 💀 0000000000000000'},
},
];

tests.forEach(({args, description, expected}) => {
return test(description, ({end, equal, throws}) => {
const {display} = chartAliasForPeer(args);

equal(display, expected.display, 'Got expected output');

return end();
});
});

0 comments on commit 3a173fe

Please sign in to comment.