Skip to content

Commit

Permalink
sets DeviceType.Unknown as default value
Browse files Browse the repository at this point in the history
only when DeviceType is not in the enum.
  • Loading branch information
hayribakici committed Nov 21, 2023
1 parent 8914227 commit beca6f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/src/models/_models.g.dart

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

1 change: 1 addition & 0 deletions lib/src/models/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Device extends Object {

/// [DeviceType], such as [DeviceType.Computer], [DeviceType.Smartphone] or
/// [DeviceType.Speaker].
@JsonKey(unknownEnumValue: DeviceType.Unknown)
DeviceType? type;

/// The current volume in percent. This may be `null`.
Expand Down
9 changes: 9 additions & 0 deletions test/data/v1/me/player/devices.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
"name": "My fridge",
"type": "Computer",
"volume_percent": 100
},
{
"id": "5fbb3ba6aa454b5534c4ba43a8c7e8e45a63ad0e",
"is_active": true,
"is_private_session": true,
"is_restricted": true,
"name": "SamsungGalaxy S3",
"type": "SmartWatch",
"volume_percent": 100
}
]
}
6 changes: 5 additions & 1 deletion test/spotify_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,18 @@ Future main() async {

test('Devices', () async {
var result = await spotify.player.devices();
expect(result.length, 1);
expect(result.length, 2);
expect(result.first.id, '5fbb3ba6aa454b5534c4ba43a8c7e8e45a63ad0e');
expect(result.first.isActive, true);
expect(result.first.isRestricted, true);
expect(result.first.isPrivateSession, true);
expect(result.first.name, 'My fridge');
expect(result.first.type, DeviceType.Computer);
expect(result.first.volumePercent, 100);

// the second entry does not have a valid [DeviceType],
// and should have `Unknown` instead.
expect(result.last.type, DeviceType.Unknown);
});

test('recentlyPlayed', () async {
Expand Down

0 comments on commit beca6f7

Please sign in to comment.