|
1 | 1 | package control |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/stretchr/testify/assert" |
| 4 | + "encoding/json" |
5 | 5 | "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/assert" |
| 8 | + "github.com/stretchr/testify/require" |
6 | 9 | ) |
7 | 10 |
|
8 | 11 | func TestApp(t *testing.T) { |
9 | 12 | client, _ := newTestClient(t) |
10 | 13 | app := newTestApp(t, &client) |
11 | 14 |
|
12 | 15 | apps, err := client.Apps() |
13 | | - assert.NoError(t, err) |
14 | | - |
15 | | - assert.NotEqual(t, len(apps), 0) |
| 16 | + require.NoError(t, err) |
| 17 | + assert.NotEmpty(t, apps) |
16 | 18 |
|
17 | 19 | a, err := client.UpdateApp(app.ID, &NewApp{TLSOnly: false}) |
18 | | - assert.NoError(t, err) |
| 20 | + require.NoError(t, err) |
19 | 21 | assert.False(t, a.TLSOnly) |
| 22 | + |
20 | 23 | newApp := NewApp{ |
21 | 24 | Status: "disabled", |
22 | 25 | TLSOnly: true, |
23 | 26 | ApnsUseSandboxEndpoint: true, |
24 | 27 | } |
25 | 28 | a, err = client.UpdateApp(app.ID, &newApp) |
26 | | - assert.NoError(t, err) |
27 | | - |
| 29 | + require.NoError(t, err) |
28 | 30 | assert.Equal(t, newApp.Status, a.Status) |
29 | 31 | assert.Equal(t, newApp.TLSOnly, a.TLSOnly) |
30 | 32 | assert.Equal(t, newApp.ApnsUseSandboxEndpoint, a.ApnsUseSandboxEndpoint) |
| 33 | +} |
| 34 | + |
| 35 | +func TestAppUnmarshalIncludesNewFields(t *testing.T) { |
| 36 | + data := `{ |
| 37 | + "id": "app123", |
| 38 | + "accountId": "acc456", |
| 39 | + "name": "Test App", |
| 40 | + "status": "enabled", |
| 41 | + "tlsOnly": true, |
| 42 | + "created": 1700000000, |
| 43 | + "modified": 1700001000, |
| 44 | + "_links": { |
| 45 | + "self": "https://control.ably.net/v1/apps/app123" |
| 46 | + } |
| 47 | + }` |
31 | 48 |
|
32 | | - err = client.DeleteApp(app.ID) |
| 49 | + var app App |
| 50 | + err := json.Unmarshal([]byte(data), &app) |
33 | 51 | assert.NoError(t, err) |
| 52 | + assert.Equal(t, "app123", app.ID) |
| 53 | + assert.Equal(t, 1700000000, app.Created) |
| 54 | + assert.Equal(t, 1700001000, app.Modified) |
| 55 | + assert.NotNil(t, app.Links) |
| 56 | + assert.Equal(t, "https://control.ably.net/v1/apps/app123", app.Links["self"]) |
34 | 57 | } |
0 commit comments