| 1 | package mobilelink |
| 2 | |
| 3 | import ( |
| 4 | "net/url" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestDeviceModel(t *testing.T) { |
| 9 | for _, tc := range []struct{ platform, raw, want string }{ |
| 10 | {"ios", "iPhone17,1", "iPhone 16 Pro"}, |
| 11 | {"ios", "iPhone18,1", "iPhone 17 Pro"}, |
| 12 | {"ios", "iPhone99,1", "iPhone (iPhone99,1)"}, |
| 13 | {"ios", "iPad99,1", "iPad (iPad99,1)"}, |
| 14 | {"android", " Google Pixel 9 Pro ", "Google Pixel 9 Pro"}, |
| 15 | } { |
| 16 | if got := DeviceModel(tc.platform, tc.raw); got != tc.want { |
| 17 | t.Errorf("%s %q: got %q, want %q", tc.platform, tc.raw, got, tc.want) |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | func TestDeviceReportOperationBoundary(t *testing.T) { |
| 23 | u := &url.URL{Path: "/api/mobile/device"} |
| 24 | if !allowed("POST", u) || allowed("GET", u) || allowed("DELETE", u) { |
| 25 | t.Fatal("device report must only accept POST") |
| 26 | } |
| 27 | u.RawQuery = "model=other" |
| 28 | if allowed("POST", u) { |
| 29 | t.Fatal("device report must not accept query parameters") |
| 30 | } |
| 31 | } |