Skip to content

Commit

Permalink
Added a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chinloyal committed Jan 19, 2021
1 parent bd51c21 commit bc5cb76
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 115 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
.pub/

build/
.idea/
6 changes: 0 additions & 6 deletions .idea/kotlinc.xml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_Plugins.xml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/libraries/KotlinJavaRuntime.xml

This file was deleted.

6 changes: 2 additions & 4 deletions .idea/modules.xml

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

6 changes: 0 additions & 6 deletions .idea/runConfigurations/example_lib_main_dart.xml

This file was deleted.

3 changes: 1 addition & 2 deletions .idea/vcs.xml

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

42 changes: 8 additions & 34 deletions .idea/workspace.xml

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

19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Pusher Channels Flutter Client

[![pub version](https://img.shields.io/pub/v/pusher_client.svg)](https://pub.dartlang.org/packages/pusher_client)
[![pub version](https://img.shields.io/pub/v/pusher_client.svg?logo=dart)](https://pub.dartlang.org/packages/pusher_client)
[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/chinloyal/pusher_client/master/LICENSE)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat)](http://twitter.com/chinloyal)
![Languages](https://img.shields.io/badge/languages-dart%20%7C%20kotlin%20%7C%20swift-blueviolet.svg)
[![Twitter](https://img.shields.io/badge/[email protected]?style=flat&logo=twitter)](https://twitter.com/chinloyal)

A Pusher Channels client plugin for Flutter targeting Android and iOS. It wraps
[pusher-websocket-java](https://github.com/pusher/pusher-websocket-java) v2.2.5 and [pusher-websocket-swift](https://github.com/pusher/pusher-websocket-swift) v8.0.0.
Expand Down Expand Up @@ -39,7 +39,6 @@ This client works with official pusher servers and laravel self hosted pusher we
- [Triggering Client Events](#triggering-client-events)
- [Accessing The Connection Socket ID](#accessing-the-connection-socket-id)
- [Resolve Common Issues](#resolve-common-issues)
- [Testing](#testing)
## Installation

Add to your pubspec.yaml
Expand Down Expand Up @@ -125,8 +124,7 @@ PusherOptions options = PusherOptions(
auth: PusherAuth(
'http://example.com/auth',
headers: {
'Authorization':
'Bearer $token',
'Authorization': 'Bearer $token',
},
),
);
Expand All @@ -151,7 +149,7 @@ pusher.onConnectionError((error) {
// Subscribe to a private channel
Channel channel = pusher.subscribe("private-orders");
// Bind to listen for events called "order-status-updated" sent to "private-orders"
// Bind to listen for events called "order-status-updated" sent to "private-orders" channel
channel.bind("order-status-updated", (PusherEvent event) {
print(event.data);
});
Expand Down Expand Up @@ -182,8 +180,7 @@ PusherAuth auth = PusherAuth(
// for auth endpoint use full url
'http://example.com/auth',
headers: {
'Authorization':
'Bearer $token',
'Authorization': 'Bearer $token',
},
);
Expand Down Expand Up @@ -321,7 +318,7 @@ Events triggered by clients are called [client events](https://pusher.com/docs/c

```dart
channel.bind("pusher:subscription_succeeded", (PusherEvent event) {
channel.trigger("client-istyping", json.encode({"name": "Bob"}));
channel.trigger("client-istyping", {"name": "Bob"});
});
```

Expand Down Expand Up @@ -376,7 +373,3 @@ If you know which domains you will connect to add:
</dict>
</dict>
```

## Testing

Both unit and integration tests are coming soon
33 changes: 30 additions & 3 deletions test/pusher_client_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
// import 'package:flutter/services.dart';
// import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pusher_client/pusher_client.dart';

void main() {
// Coming very soon
WidgetsFlutterBinding.ensureInitialized();
MethodChannel channel =
const MethodChannel('com.github.chinloyal/pusher_client');
group('PusherClient Test | ', () {
setUp(() {
channel.setMockMethodCallHandler((call) {
switch (call.method) {
case 'init':
return null;
case 'connect':
return null;
default:
throw UnimplementedError();
}
});
});

test('Pusher client returns a singleton', () {
var pusher1 = PusherClient('key', PusherOptions());
var pusher2 = PusherClient('key', PusherOptions());

expect(pusher1.hashCode, pusher2.hashCode);
});

// test()
});
}

0 comments on commit bc5cb76

Please sign in to comment.