Skip to content

Commit

Permalink
tests: add rest test for play (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
xx4h authored Oct 12, 2024
1 parent 5b225c5 commit 2752d33
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/rest/play_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2024 Fabian `xx4h` Sylvester
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package rest

import (
"testing"
)

func Test_PlayMusic(t *testing.T) {
ms := mockServer(t)
h := &Hass{
APIURL: ms.URL,
Token: "test_token",
}
defer ms.Close()
obj, action, sub, err := h.PlayMusic("player1", "testdata/fake.mp3", "fake.mp3")
if err != nil {
t.Errorf("Error playing: %v", err)
}
if obj != "player1" {
t.Errorf("got %s, want player1", obj)
}
if action != "playing fake.mp3" {
t.Errorf("got %s, want 'playing fake.mp3'", action)
}
if sub != "media_player" {
t.Errorf("got %s, want media_player", sub)
}
}
56 changes: 56 additions & 0 deletions pkg/rest/testdata/player1_media_player_play_media_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[
{
"entity_id": "media_player.player1",
"state": "idle",
"attributes": {
"volume_level": 0.30000001192092896,
"is_volume_muted": false,
"media_content_id": "http://10.10.10.10:1337/fake.mp3",
"media_content_type": "music",
"media_duration": 3.160816,
"media_position": 0,
"media_position_updated_at": "2024-10-12T20:57:22.888305+00:00",
"app_id": "ABCDE123",
"app_name": "Default Media Receiver",
"entity_picture_local": null,
"device_class": "speaker",
"friendly_name": "Player 1",
"supported_features": 152463
},
"last_changed": "2024-10-12T20:56:54.692016+00:00",
"last_reported": "2024-10-12T20:57:22.888625+00:00",
"last_updated": "2024-10-12T20:57:22.888625+00:00",
"context": {
"id": "ABDCDEFGHIJKLMNOPQRSTUVW01",
"parent_id": null,
"user_id": "someuseridhash"
}
},
{
"entity_id": "media_player.player1",
"state": "playing",
"attributes": {
"volume_level": 0.30000001192092896,
"is_volume_muted": false,
"media_content_id": "http://10.10.10.10:1337/fake.mp3",
"media_content_type": "music",
"media_duration": 3.160816,
"media_position": 0,
"media_position_updated_at": "2024-10-12T20:57:23.012272+00:00",
"app_id": "ABCDE123",
"app_name": "Default Media Receiver",
"entity_picture_local": null,
"device_class": "speaker",
"friendly_name": "Player 1",
"supported_features": 152463
},
"last_changed": "2024-10-12T20:57:23.012695+00:00",
"last_reported": "2024-10-12T20:57:23.012695+00:00",
"last_updated": "2024-10-12T20:57:23.012695+00:00",
"context": {
"id": "ABDCDEFGHIJKLMNOPQRSTUVW01",
"parent_id": null,
"user_id": "someuseridhash"
}
}
]

0 comments on commit 2752d33

Please sign in to comment.