Skip to content

Commit

Permalink
Refactor SpinifyServerSubscription test to use fakeAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Jun 12, 2024
1 parent 5b0ecd6 commit 21e3d3d
Showing 1 changed file with 66 additions and 63 deletions.
129 changes: 66 additions & 63 deletions test/unit/server_subscription_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,76 +5,79 @@ import 'package:test/test.dart';
void main() {
group('SpinifyServerSubscription', () {
test(
'Emulate server subscription',
() => fakeAsync((async) {
final client = Spinify(
config: SpinifyConfig(
transportBuilder: $createFakeSpinifyTransport(
overrideCommand: (command) => switch (command) {
SpinifyConnectRequest request => SpinifyConnectResult(
'Emulate server subscription',
() => fakeAsync(
(async) {
final client = Spinify(
config: SpinifyConfig(
transportBuilder: $createFakeSpinifyTransport(
overrideCommand: (command) => switch (command) {
SpinifyConnectRequest request => SpinifyConnectResult(
id: request.id,
timestamp: DateTime.now(),
client: 'fake',
version: '0.0.1',
expires: false,
ttl: null,
data: null,
subs: <String, SpinifySubscribeResult>{
'notification:index': SpinifySubscribeResult(
id: request.id,
timestamp: DateTime.now(),
client: 'fake',
version: '0.0.1',
data: const <int>[],
expires: false,
ttl: null,
data: null,
subs: <String, SpinifySubscribeResult>{
'notification:index': SpinifySubscribeResult(
id: request.id,
timestamp: DateTime.now(),
positioned: false,
publications: <SpinifyPublication>[
SpinifyPublication(
channel: 'notification:index',
data: const <int>[],
expires: false,
ttl: null,
positioned: false,
publications: <SpinifyPublication>[
SpinifyPublication(
channel: 'notification:index',
data: const <int>[],
info: SpinifyClientInfo(
client: 'fake',
user: 'fake',
channelInfo: const <int>[],
connectionInfo: const <int>[],
),
timestamp: DateTime.now(),
tags: const <String, String>{
'type': 'notification',
},
offset: Int64.ZERO,
),
],
recoverable: false,
recovered: false,
since: (epoch: '...', offset: Int64.ZERO),
wasRecovering: false,
info: SpinifyClientInfo(
client: 'fake',
user: 'fake',
channelInfo: const <int>[],
connectionInfo: const <int>[],
),
timestamp: DateTime.now(),
tags: const <String, String>{
'type': 'notification',
},
offset: Int64.ZERO,
),
},
pingInterval: const Duration(seconds: 25),
sendPong: false,
session: 'fake',
node: 'fake',
],
recoverable: false,
recovered: false,
since: (epoch: '...', offset: Int64.ZERO),
wasRecovering: false,
),
_ => null,
},
),
),
)..connect('ws://localhost:8000/connection/websocket');
async.elapse(client.config.timeout);
expect(
client.subscriptions.server,
isA<Map<String, SpinifyServerSubscription>>()
.having(
(s) => s.length,
'length',
1,
)
.having(
(s) => s['notification:index'],
'notification:index',
isA<SpinifyServerSubscription>(),
},
pingInterval: const Duration(seconds: 25),
sendPong: false,
session: 'fake',
node: 'fake',
),
);
}));
_ => null,
},
),
),
)..connect('ws://localhost:8000/connection/websocket');
async.elapse(client.config.timeout);
expect(
client.subscriptions.server,
isA<Map<String, SpinifyServerSubscription>>()
.having(
(s) => s.length,
'length',
1,
)
.having(
(s) => s['notification:index'],
'notification:index',
isA<SpinifyServerSubscription>(),
),
);
},
),
);
});
}

0 comments on commit 21e3d3d

Please sign in to comment.