Commit d2d025b4ddd924dc333fd8fbc3915624a26c9f09
update to rename for caps
Signed-off-by: wanderer <mjbecze@gmail.com>wanderer committed on 11/14/2017, 12:56:46 AM
Parent: bfd6fba3723499dceee6f8c9fd1c2af03931c986
Files changed
index.js | changed |
tests/index.js | changed |
index.js | ||
---|---|---|
@@ -11,9 +11,9 @@ | ||
11 | 11 … | constructor (opts = {}) { |
12 | 12 … | const defaults = { |
13 | 13 … | ticks: 0, |
14 | 14 … | data: new ArrayBuffer([]), |
15 | - ports: [] | |
15 … | + caps: [] | |
16 | 16 … | } |
17 | 17 … | |
18 | 18 … | this._opts = Object.assign(defaults, opts) |
19 | 19 … | |
@@ -38,10 +38,10 @@ | ||
38 | 38 … | /** |
39 | 39 … | * Returns an array of ports that a message is carrying |
40 | 40 … | * @returns {[]} |
41 | 41 … | */ |
42 | - get ports () { | |
43 | - return this._opts.ports | |
42 … | + get caps () { | |
43 … | + return this._opts.caps | |
44 | 44 … | } |
45 | 45 … | |
46 | 46 … | /** |
47 | 47 … | * Returns the messages payload |
@@ -54,10 +54,10 @@ | ||
54 | 54 … | /** |
55 | 55 … | * Returns the port from which the message arrived |
56 | 56 … | * @returns {*} |
57 | 57 … | */ |
58 | - get fromPort () { | |
59 | - return this._fromPort | |
58 … | + get from () { | |
59 … | + return this._from | |
60 | 60 … | } |
61 | 61 … | |
62 | 62 … | /** |
63 | 63 … | * returns the number of hops a packet has undergone |
tests/index.js | |||
---|---|---|---|
@@ -1,24 +1,27 @@ | |||
1 | 1 … | const tape = require('tape') | |
2 | 2 … | const Message = require('../') | |
3 | 3 … | ||
4 | 4 … | tape('message API tests', async t => { | |
5 | - const aPort = {} | ||
6 | - const json = '{"ticks":77,"data":{"type":"Buffer","data":[116,101,115,116]},"ports":[{}]}' | ||
5 … | + const capA = {} | ||
6 … | + const json = '{"ticks":77,"data":{"type":"Buffer","data":[116,101,115,116]},"caps":[{}]}' | ||
7 | 7 … | ||
8 | 8 … | const params = { | |
9 | 9 … | data: Buffer.from('test'), | |
10 | - ports: [aPort], | ||
10 … | + caps: [capA], | ||
11 | 11 … | ticks: 77 | |
12 | 12 … | } | |
13 | 13 … | ||
14 | 14 … | let message = new Message(params) | |
15 | - message._fromPort = 'test' | ||
15 … | + message._from = 'test' | ||
16 | 16 … | ||
17 | - t.equals(message.fromPort, 'test', 'to getter should work') | ||
18 | - t.equals(message.ports[0], aPort, 'to getter should work') | ||
17 … | + t.equals(message.from, 'test', 'to getter should work') | ||
18 … | + t.equals(message.caps[0], capA, 'to getter should work') | ||
19 | 19 … | t.equals(message.data.toString(), 'test', 'to getter should work') | |
20 | 20 … | t.equals(message.ticks, 77, 'resources getter should work') | |
21 | 21 … | t.equals(message.hops, 0, 'hops should return correctly') | |
22 | 22 … | t.equals(JSON.stringify(message), json) | |
23 … | + | ||
24 … | + message = new Message() | ||
25 … | + t.equals(message.ticks, 0, 'resources getter should work') | ||
23 | 26 … | t.end() | |
24 | 27 … | }) |
Built with git-ssb-web