Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
flowagent
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
node-red
flowagent
Commits
936fad75
Commit
936fad75
authored
Apr 19, 2020
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change toicstore from promise to return
parent
b163fa47
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
37 deletions
+34
-37
spec/topicstore.js
+26
-26
topicstore.js
+8
-11
No files found.
spec/topicstore.js
View file @
936fad75
...
...
@@ -18,49 +18,49 @@ describe("Test TopicStore", function () {
done
();
});
it
(
"After addTopic(), topicstore should hold that topic"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
it
(
"After addTopic(), topicstore should hold that topic"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
it
(
"If add duplicate topics, topicstore.addTopic() should return false"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
it
(
"If add duplicate topics, topicstore.addTopic() should return false"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
it
(
"If add more topics, topicstore.addTopic() should hold all"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/ok'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/bye'
,
'1234.5678'
)).
to
.
equal
(
true
);
it
(
"If add more topics, topicstore.addTopic() should hold all"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/ok'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/bye'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
,
'@msg/ok'
,
'@msg/bye'
]);
});
it
(
"If add duplicate topics by different block, topicstore.addTopic() should return false"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
it
(
"If add duplicate topics by different block, topicstore.addTopic() should return false"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
getTopics
()).
to
.
deep
.
equal
([
'@msg/hello'
]);
});
it
(
"topicstore.delTopic() should return true if one block holds that topic"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
it
(
"topicstore.delTopic() should return true if one block holds that topic"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
});
it
(
"topicstore.delTopic() should return false if two block holds that topic"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
it
(
"topicstore.delTopic() should return false if two block holds that topic"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
});
it
(
"topicstore.delTopic() should return true only if delete by the last block holding that topic"
,
async
function
()
{
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
it
(
"topicstore.delTopic() should return true only if delete by the last block holding that topic"
,
function
()
{
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
addTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
expect
(
await
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.9012'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.1234'
)).
to
.
equal
(
false
);
expect
(
topicstore
.
delTopic
(
'@msg/hello'
,
'1234.5678'
)).
to
.
equal
(
true
);
});
...
...
topicstore.js
View file @
936fad75
...
...
@@ -23,41 +23,38 @@ TopicStore.prototype.getRawData = function() {
}
TopicStore
.
prototype
.
addTopic
=
function
(
topic
,
blockid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
this
.
data
[
topic
]
=
[
blockid
];
resolve
(
true
)
return
(
true
)
}
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
if
(
p
>=
0
)
{
resolve
(
false
);
return
(
false
);
}
else
{
this
.
data
[
topic
].
push
(
blockid
);
resolve
(
false
)
return
(
false
)
}
}
});
}
TopicStore
.
prototype
.
delTopic
=
function
(
topic
,
blockid
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
data
[
topic
]
==
undefined
||
this
.
data
[
topic
].
length
==
0
)
{
resolve
(
true
);
// still force unsub
return
(
true
);
// still force unsub
}
else
{
let
p
=
this
.
data
[
topic
].
indexOf
(
blockid
);
if
(
p
>=
0
)
{
this
.
data
[
topic
].
splice
(
p
,
1
);
if
(
this
.
data
[
topic
].
length
==
0
)
resolve
(
true
);
else
resolve
(
false
);
if
(
this
.
data
[
topic
].
length
==
0
)
return
(
true
);
else
return
(
false
);
}
else
{
resolve
(
false
);
return
(
false
);
}
}
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment