|
7 | 7 | "github.com/massdriver-cloud/mass/internal/api" |
8 | 8 | "github.com/massdriver-cloud/mass/internal/gqlmock" |
9 | 9 | "github.com/massdriver-cloud/massdriver-sdk-go/massdriver/client" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
10 | 12 | ) |
11 | 13 |
|
12 | 14 | func TestGetPackage(t *testing.T) { |
@@ -122,3 +124,90 @@ func TestResetPackage(t *testing.T) { |
122 | 124 | t.Errorf("got %v, wanted %v", pkg.Status, "ready") |
123 | 125 | } |
124 | 126 | } |
| 127 | + |
| 128 | +func TestGetPackage_NilDeployments(t *testing.T) { |
| 129 | + pkgName := "ecomm-prod-cache" |
| 130 | + |
| 131 | + gqlClient := gqlmock.NewClientWithSingleJSONResponse(map[string]any{ |
| 132 | + "data": map[string]any{ |
| 133 | + "package": map[string]any{ |
| 134 | + "slug": pkgName, |
| 135 | + "status": "provisioned", |
| 136 | + "deployedVersion": nil, |
| 137 | + "latestDeployment": nil, |
| 138 | + "activeDeployment": nil, |
| 139 | + "bundle": map[string]any{ |
| 140 | + "id": "bundle-id", |
| 141 | + }, |
| 142 | + "manifest": map[string]any{ |
| 143 | + "id": "manifest-id", |
| 144 | + }, |
| 145 | + "environment": map[string]any{ |
| 146 | + "id": "target-id", |
| 147 | + }, |
| 148 | + }, |
| 149 | + }, |
| 150 | + }) |
| 151 | + mdClient := client.Client{ |
| 152 | + GQL: gqlClient, |
| 153 | + } |
| 154 | + |
| 155 | + got, err := api.GetPackage(t.Context(), &mdClient, pkgName) |
| 156 | + require.NoError(t, err) |
| 157 | + |
| 158 | + assert.Nil(t, got.DeployedVersion, "DeployedVersion should be nil for never-deployed packages") |
| 159 | + assert.Nil(t, got.LatestDeployment, "LatestDeployment should be nil when not present") |
| 160 | + assert.Nil(t, got.ActiveDeployment, "ActiveDeployment should be nil when not present") |
| 161 | +} |
| 162 | + |
| 163 | +func TestGetPackage_WithDeployments(t *testing.T) { |
| 164 | + pkgName := "ecomm-prod-cache" |
| 165 | + version := "0.1.0" |
| 166 | + |
| 167 | + gqlClient := gqlmock.NewClientWithSingleJSONResponse(map[string]any{ |
| 168 | + "data": map[string]any{ |
| 169 | + "package": map[string]any{ |
| 170 | + "slug": pkgName, |
| 171 | + "status": "provisioned", |
| 172 | + "deployedVersion": version, |
| 173 | + "latestDeployment": map[string]any{ |
| 174 | + "id": "deploy-1", |
| 175 | + "status": "COMPLETED", |
| 176 | + "action": "PROVISION", |
| 177 | + "version": version, |
| 178 | + "createdAt": "2026-01-15T10:30:00Z", |
| 179 | + }, |
| 180 | + "activeDeployment": map[string]any{ |
| 181 | + "id": "deploy-1", |
| 182 | + "status": "COMPLETED", |
| 183 | + "action": "PROVISION", |
| 184 | + "version": version, |
| 185 | + "createdAt": "2026-01-15T10:30:00Z", |
| 186 | + }, |
| 187 | + "bundle": map[string]any{ |
| 188 | + "id": "bundle-id", |
| 189 | + }, |
| 190 | + "manifest": map[string]any{ |
| 191 | + "id": "manifest-id", |
| 192 | + }, |
| 193 | + "environment": map[string]any{ |
| 194 | + "id": "target-id", |
| 195 | + }, |
| 196 | + }, |
| 197 | + }, |
| 198 | + }) |
| 199 | + mdClient := client.Client{ |
| 200 | + GQL: gqlClient, |
| 201 | + } |
| 202 | + |
| 203 | + got, err := api.GetPackage(t.Context(), &mdClient, pkgName) |
| 204 | + require.NoError(t, err) |
| 205 | + |
| 206 | + require.NotNil(t, got.DeployedVersion) |
| 207 | + assert.Equal(t, version, *got.DeployedVersion) |
| 208 | + require.NotNil(t, got.LatestDeployment) |
| 209 | + assert.Equal(t, "deploy-1", got.LatestDeployment.ID) |
| 210 | + assert.Equal(t, "COMPLETED", got.LatestDeployment.Status) |
| 211 | + require.NotNil(t, got.ActiveDeployment) |
| 212 | + assert.Equal(t, "deploy-1", got.ActiveDeployment.ID) |
| 213 | +} |
0 commit comments