1+ /*
2+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+ * SPDX-License-Identifier: Apache-2.0.
4+ */
5+
6+ import * as mqtt_shared_browser from "./mqtt_shared_browser" ;
7+
8+ test ( 'MQTT topic properties - valid topic filter' , async ( ) => {
9+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/b/c" , true ) . isValid ) . toEqual ( true ) ;
10+ expect ( mqtt_shared_browser . computeTopicProperties ( "#" , true ) . isValid ) . toEqual ( true ) ;
11+ expect ( mqtt_shared_browser . computeTopicProperties ( "/#" , true ) . isValid ) . toEqual ( true ) ;
12+ expect ( mqtt_shared_browser . computeTopicProperties ( "sports/basketball/#" , true ) . isValid ) . toEqual ( true ) ;
13+ expect ( mqtt_shared_browser . computeTopicProperties ( "+" , true ) . isValid ) . toEqual ( true ) ;
14+ expect ( mqtt_shared_browser . computeTopicProperties ( "/+" , true ) . isValid ) . toEqual ( true ) ;
15+ expect ( mqtt_shared_browser . computeTopicProperties ( "+/a" , true ) . isValid ) . toEqual ( true ) ;
16+ expect ( mqtt_shared_browser . computeTopicProperties ( "+/basketball/#" , true ) . isValid ) . toEqual ( true ) ;
17+ expect ( mqtt_shared_browser . computeTopicProperties ( "washington/+/player1" , true ) . isValid ) . toEqual ( true ) ;
18+ } ) ;
19+
20+ test ( 'MQTT topic properties - invalid topic filter' , async ( ) => {
21+ expect ( mqtt_shared_browser . computeTopicProperties ( "" , true ) . isValid ) . toEqual ( false ) ;
22+ expect ( mqtt_shared_browser . computeTopicProperties ( "derp+" , true ) . isValid ) . toEqual ( false ) ;
23+ expect ( mqtt_shared_browser . computeTopicProperties ( "derp+/" , true ) . isValid ) . toEqual ( false ) ;
24+ expect ( mqtt_shared_browser . computeTopicProperties ( "derp#/" , true ) . isValid ) . toEqual ( false ) ;
25+ expect ( mqtt_shared_browser . computeTopicProperties ( "#/a" , true ) . isValid ) . toEqual ( false ) ;
26+ expect ( mqtt_shared_browser . computeTopicProperties ( "sport/basketball#" , true ) . isValid ) . toEqual ( false ) ;
27+ expect ( mqtt_shared_browser . computeTopicProperties ( "sport/basketball/#/ranking" , true ) . isValid ) . toEqual ( false ) ;
28+ } ) ;
29+
30+ test ( 'MQTT topic properties - shared filter' , async ( ) => {
31+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/b//" , true ) . isShared ) . toEqual ( true ) ;
32+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/a/b" , true ) . isShared ) . toEqual ( true ) ;
33+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/a/b/c" , true ) . isShared ) . toEqual ( true ) ;
34+ } ) ;
35+
36+ test ( 'MQTT topic properties - not shared filter' , async ( ) => {
37+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/b/c" , true ) . isShared ) . toEqual ( false ) ;
38+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share//c" , true ) . isShared ) . toEqual ( false ) ;
39+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/a" , true ) . isShared ) . toEqual ( false ) ;
40+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/+/a" , true ) . isShared ) . toEqual ( false ) ;
41+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/#/a" , true ) . isShared ) . toEqual ( false ) ;
42+ expect ( mqtt_shared_browser . computeTopicProperties ( "$share/b/" , true ) . isShared ) . toEqual ( false ) ;
43+ } ) ;
44+
45+ test ( 'MQTT topic properties - has wildcard' , async ( ) => {
46+ expect ( mqtt_shared_browser . computeTopicProperties ( "#" , true ) . hasWildcard ) . toEqual ( true ) ;
47+ expect ( mqtt_shared_browser . computeTopicProperties ( "+" , true ) . hasWildcard ) . toEqual ( true ) ;
48+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/+/+" , true ) . hasWildcard ) . toEqual ( true ) ;
49+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/b/#" , true ) . hasWildcard ) . toEqual ( true ) ;
50+ } ) ;
51+
52+ test ( 'MQTT topic properties - does not have wildcard' , async ( ) => {
53+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/b/c" , true ) . hasWildcard ) . toEqual ( false ) ;
54+ expect ( mqtt_shared_browser . computeTopicProperties ( "/" , true ) . hasWildcard ) . toEqual ( false ) ;
55+ } ) ;
56+
57+ test ( 'MQTT topic properties - valid topic' , async ( ) => {
58+ expect ( mqtt_shared_browser . computeTopicProperties ( "a/b/c" , false ) . isValid ) . toEqual ( true ) ;
59+ expect ( mqtt_shared_browser . computeTopicProperties ( "/" , false ) . isValid ) . toEqual ( true ) ;
60+ expect ( mqtt_shared_browser . computeTopicProperties ( "///a" , false ) . isValid ) . toEqual ( true ) ;
61+ } ) ;
62+
63+ test ( 'MQTT topic properties - invalid topic' , async ( ) => {
64+ expect ( mqtt_shared_browser . computeTopicProperties ( "" , false ) . isValid ) . toEqual ( false ) ;
65+ expect ( mqtt_shared_browser . computeTopicProperties ( "#" , false ) . isValid ) . toEqual ( false ) ;
66+ expect ( mqtt_shared_browser . computeTopicProperties ( "/#" , false ) . isValid ) . toEqual ( false ) ;
67+ expect ( mqtt_shared_browser . computeTopicProperties ( "sports/basketball/#" , false ) . isValid ) . toEqual ( false ) ;
68+ expect ( mqtt_shared_browser . computeTopicProperties ( "+" , false ) . isValid ) . toEqual ( false ) ;
69+ expect ( mqtt_shared_browser . computeTopicProperties ( "/+" , false ) . isValid ) . toEqual ( false ) ;
70+ expect ( mqtt_shared_browser . computeTopicProperties ( "+/a" , false ) . isValid ) . toEqual ( false ) ;
71+ expect ( mqtt_shared_browser . computeTopicProperties ( "+/basketball/#" , false ) . isValid ) . toEqual ( false ) ;
72+ expect ( mqtt_shared_browser . computeTopicProperties ( "washington/+/player1" , false ) . isValid ) . toEqual ( false ) ;
73+ } ) ;
0 commit comments