@@ -4,32 +4,126 @@ import Capacitor
44
55class PluginTests : XCTestCase {
66
7- override func setUp( ) {
8- super. setUp ( )
9- // Put setup code here. This method is called before the invocation of each test method in the class.
10- }
11-
12- override func tearDown( ) {
13- // Put teardown code here. This method is called after the invocation of each test method in the class.
14- super. tearDown ( )
15- }
16-
17- func testSetUp( ) {
18- // This is an example of a functional test case for a plugin.
19- // Use XCTAssert and related functions to verify your tests produce the correct results.
20-
21- let key = " SAMPLE_KEY "
22- let plugin = MyPlugin ( )
23-
24- let call = CAPPluginCall ( callbackId: " test " , options: [
25- " key " : key
7+ override func setUp( ) {
8+ super. setUp ( )
9+ // Put setup code here. This method is called before the invocation of each test method in the class.
10+ }
11+
12+ override func tearDown( ) {
13+ // Put teardown code here. This method is called after the invocation of each test method in the class.
14+ super. tearDown ( )
15+ }
16+
17+ func testSetUp( ) {
18+
19+ let plugin = SegmentPlugin ( )
20+
21+
22+ ( {
23+ let expectation = XCTestExpectation ( description: " [SET_UP] NO_KEY " ) ;
24+ let call = CAPPluginCall ( callbackId: " test " , options: [ : ] , success: { ( result, call) in
25+ XCTFail ( " 🤦♂️ Success callback should not have been called with empty key " )
26+ expectation. fulfill ( )
27+ } , error: { ( err: CAPPluginCallError ? ) in
28+ XCTAssertEqual ( err!. message, " segment key not specified " ) ;
29+ XCTAssertEqual ( err!. data![ " code " ] ! as? String , " [SET_UP] NO_KEY " ) ;
30+ // print("👎 err message: " + err!.message + ". data: " + err!.data!.description);
31+ expectation. fulfill ( )
32+ } ) ;
33+ plugin. setUp ( call!)
34+ wait ( for: [ expectation] , timeout: 1 ) ;
35+ } ) ( ) ;
36+
37+
38+ ( {
39+ let expectation = XCTestExpectation ( description: " [SET_UP] SUCCESS " ) ;
40+ let call = CAPPluginCall ( callbackId: " test " , options: [
41+ " key " : " test_segment_key "
42+ ] , success: { ( result, call) in
43+ XCTAssertEqual ( result!. data. count, 0 ) ;
44+ expectation. fulfill ( )
45+ } , error: { ( err: CAPPluginCallError ? ) in
46+ XCTFail ( " 🤦♂️ Error callback should not have been called " )
47+ expectation. fulfill ( )
48+ } ) ;
49+ plugin. setUp ( call!)
50+ wait ( for: [ expectation] , timeout: 1 ) ;
51+ } ) ( ) ;
52+
53+
54+ ( {
55+ let expectation = XCTestExpectation ( description: " [SET_UP] DUPE_CALL " ) ;
56+ let call = CAPPluginCall ( callbackId: " test " , options: [
57+ " key " : " test_segment_key "
2658 ] , success: { ( result, call) in
27- // let message = result!.data["message"] as? String
28- // XCTAssertEqual(message, "✅ Success")
29- } , error: { ( err) in
30- XCTFail ( " Error shouldn't have been called " )
31- } )
32-
33- plugin. setUp ( call!)
34- }
59+ XCTFail ( " 🤦♂️ Success callback should not have been called " )
60+ expectation. fulfill ( )
61+ } , error: { ( err: CAPPluginCallError ? ) in
62+ XCTAssertEqual ( err!. message, " segment already set up " ) ;
63+ XCTAssertEqual ( err!. data![ " code " ] ! as? String , " [SET_UP] DUPE_CALL " ) ;
64+ expectation. fulfill ( )
65+ } ) ;
66+ plugin. setUp ( call!)
67+ wait ( for: [ expectation] , timeout: 1 ) ;
68+ } ) ( ) ;
69+
70+ // TODO: test location services and lifecycle
71+
72+ }
73+
74+ func testIdentify( ) {
75+
76+ let plugin = SegmentPlugin ( ) ;
77+
78+
79+ ( {
80+ let expectation = XCTestExpectation ( description: " [IDENTIFY] NOT_SET_UP " ) ;
81+ let call = CAPPluginCall ( callbackId: " test " , options: [ : ] , success: { ( result, call) in
82+ XCTFail ( " 🤦♂️ Success callback should not have been called " )
83+ expectation. fulfill ( )
84+ } , error: { ( err: CAPPluginCallError ? ) in
85+ XCTAssertEqual ( err!. message, " segment not set up " ) ;
86+ XCTAssertEqual ( err!. data![ " code " ] ! as? String , " [IDENTIFY] NOT_SET_UP " ) ;
87+ expectation. fulfill ( )
88+ } ) ;
89+ plugin. identify ( call!)
90+ wait ( for: [ expectation] , timeout: 1 ) ;
91+ } ) ( ) ;
92+
93+
94+ // ({
95+ // let expectation = XCTestExpectation(description: "[IDENTIFY] NO_USER_ID");
96+ // let call = CAPPluginCall(callbackId: "test", options: [
97+ // "key": "test_segment_key"
98+ // ], success: { (result, call) in
99+ // XCTFail("🤦♂️ Success callback should not have been called")
100+ // expectation.fulfill()
101+ // }, error: { (err: CAPPluginCallError?) in
102+ // XCTAssertEqual(err!.message, "segment already set up");
103+ // XCTAssertEqual(err!.data!["code"]! as? String, "[SET_UP] DUPE_CALL");
104+ // expectation.fulfill()
105+ // });
106+ // plugin.setUp(call!)
107+ // wait(for: [expectation], timeout: 1);
108+ // })();
109+ //
110+ //
111+ // ({
112+ // let expectation = XCTestExpectation(description: "[IDENTIFY] SUCCESS");
113+ // let call = CAPPluginCall(callbackId: "test", options: [
114+ // "key": "test_segment_key"
115+ // ], success: { (result, call) in
116+ // XCTFail("🤦♂️ Success callback should not have been called")
117+ // expectation.fulfill()
118+ // }, error: { (err: CAPPluginCallError?) in
119+ // XCTAssertEqual(err!.message, "segment already set up");
120+ // XCTAssertEqual(err!.data!["code"]! as? String, "[SET_UP] DUPE_CALL");
121+ // expectation.fulfill()
122+ // });
123+ // plugin.setUp(call!)
124+ // wait(for: [expectation], timeout: 1);
125+ // })();
126+
127+ }
128+
35129}
0 commit comments