@hot-updater/test-utils 1.2.0-rc.26 → 1.2.0-rc.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -65,9 +65,9 @@ declare const setupBundleMethodsTestSuite: (options: {
65
65
  /**
66
66
  * Core's operations through admin API protocol 2 that the bundle and catalog
67
67
  * suites leave out: channels, deploy refusals, promotion, preflights, a
68
- * bundle's patch children, and the native build registry. Each test deletes
69
- * what it wrote, except a native build, which the registry keeps: its IDs
70
- * and channel are the test's own.
68
+ * bundle's patch children, the native build registry, and the iOS device
69
+ * registry. Each test deletes what it wrote, except a native build, which the
70
+ * registry keeps: its IDs and channel are the test's own.
71
71
  */
72
72
  declare const setupCoreAdminTestSuite: (options: {
73
73
  readonly getClient: () => HttpTestClient;
package/dist/index.mjs CHANGED
@@ -238,9 +238,9 @@ const setupBundleMethodsTestSuite = (options) => {
238
238
  /**
239
239
  * Core's operations through admin API protocol 2 that the bundle and catalog
240
240
  * suites leave out: channels, deploy refusals, promotion, preflights, a
241
- * bundle's patch children, and the native build registry. Each test deletes
242
- * what it wrote, except a native build, which the registry keeps: its IDs
243
- * and channel are the test's own.
241
+ * bundle's patch children, the native build registry, and the iOS device
242
+ * registry. Each test deletes what it wrote, except a native build, which the
243
+ * registry keeps: its IDs and channel are the test's own.
244
244
  */
245
245
  const setupCoreAdminTestSuite = (options) => {
246
246
  describe("Core admin API", () => {
@@ -663,7 +663,8 @@ const setupCoreAdminTestSuite = (options) => {
663
663
  expect(plainBuild).toMatchObject({
664
664
  is_sandbox: false,
665
665
  is_store_build: false,
666
- sandbox_url_scheme: null
666
+ sandbox_url_scheme: null,
667
+ export_method: null
667
668
  });
668
669
  expect((await adminJson(`/native-builds/${sandboxBuild.id}`)).data).toEqual(sandboxBuild);
669
670
  expect((await adminJson(`/native-builds/${plainBuild.id}`)).data).toEqual(plainBuild);
@@ -672,6 +673,96 @@ const setupCoreAdminTestSuite = (options) => {
672
673
  expect(marked.status).toBe(400);
673
674
  await marked.text();
674
675
  });
676
+ it("requests, approves, renames, records, and removes iOS devices", async () => {
677
+ const udid = namespace.replaceAll("-", "").padEnd(40, "0");
678
+ const device = async (path, init) => (await adminJson(path, init)).data;
679
+ const requested = await adminJson("/ios-devices", jsonRequest("POST", {
680
+ udid: udid.toUpperCase(),
681
+ name: "Kim's iPhone",
682
+ requestedBy: "kim@team.dev"
683
+ }));
684
+ expect(requested.data.created).toBe(true);
685
+ const { id } = requested.data.device;
686
+ expect(requested.data.device).toMatchObject({
687
+ udid,
688
+ status: "pending",
689
+ requested_by: "kim@team.dev"
690
+ });
691
+ try {
692
+ const again = await adminJson("/ios-devices", jsonRequest("POST", {
693
+ udid,
694
+ name: "Other",
695
+ requestedBy: null
696
+ }));
697
+ expect(again.data).toEqual({
698
+ device: requested.data.device,
699
+ created: false
700
+ });
701
+ const raced = `${udid.slice(0, 39)}f`;
702
+ const racing = await Promise.all(["Other", "Another"].map((name) => adminJson("/ios-devices", jsonRequest("POST", {
703
+ udid: raced,
704
+ name,
705
+ requestedBy: null
706
+ }))));
707
+ expect(racing.map(({ data }) => data.created).sort()).toEqual([false, true]);
708
+ expect(racing[0].data.device.id).toBe(racing[1].data.device.id);
709
+ await adminJson(`/ios-devices/${racing[0].data.device.id}`, jsonRequest("DELETE"));
710
+ expect(await device(`/ios-devices/udid/${udid}`)).toEqual(requested.data.device);
711
+ const pending = await adminJson("/ios-devices?status=pending&limit=500");
712
+ expect(pending.data.map((row) => row.id)).toContain(id);
713
+ const approval = await device(`/ios-devices/${id}/approval`, jsonRequest("POST", { approvedBy: "lead@team.dev" }));
714
+ expect(approval).toMatchObject({
715
+ status: "approved",
716
+ approved_by: "lead@team.dev"
717
+ });
718
+ expect(await device(`/ios-devices/${id}`, jsonRequest("PATCH", { name: "Kim's work iPhone" }))).toMatchObject({
719
+ name: "Kim's work iPhone",
720
+ status: "approved"
721
+ });
722
+ const registered = await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
723
+ seen: {
724
+ status: "approved",
725
+ approvedAtMs: approval.approved_at_ms
726
+ },
727
+ issuerId: "issuer-a",
728
+ outcome: "registered"
729
+ }));
730
+ expect(registered).toMatchObject({
731
+ status: "registered",
732
+ apple_issuer_id: "issuer-a"
733
+ });
734
+ expect(await device(`/ios-devices/${id}/outcome`, jsonRequest("POST", {
735
+ seen: {
736
+ status: "approved",
737
+ approvedAtMs: 1
738
+ },
739
+ issuerId: "issuer-a",
740
+ outcome: "missing"
741
+ }))).toBeNull();
742
+ const claims = await Promise.all(["issuer-a", "issuer-b"].map((issuerId) => adminJson("/ios-devices/account", jsonRequest("POST", { issuerId }))));
743
+ const owner = claims.find(({ data }) => data.claimed)?.data.issuerId;
744
+ expect(claims.filter(({ data }) => data.claimed)).toHaveLength(1);
745
+ expect(claims.map(({ data }) => data.issuerId)).toEqual([owner, owner]);
746
+ const buildId = bundleRow("90").id;
747
+ const marked = await admin("/ios-devices/in-build", jsonRequest("POST", {
748
+ buildId,
749
+ ids: [id]
750
+ }));
751
+ expect(marked.status).toBe(204);
752
+ expect((await device(`/ios-devices/udid/${udid}`))?.build_id).toBe(buildId);
753
+ const refused = await admin("/ios-devices", jsonRequest("POST", {
754
+ udid: "1234",
755
+ name: "x",
756
+ requestedBy: null
757
+ }));
758
+ expect(refused.status).toBe(400);
759
+ await refused.text();
760
+ } finally {
761
+ await adminJson(`/ios-devices/${id}`, jsonRequest("DELETE"));
762
+ }
763
+ expect(await device(`/ios-devices/udid/${udid}`)).toBeNull();
764
+ expect(await device(`/ios-devices/${id}`, jsonRequest("DELETE"))).toBeNull();
765
+ });
675
766
  it("lists the patches that start from a bundle", async () => {
676
767
  const base = bundleRow("50");
677
768
  const target = bundleRow("51");
@@ -3374,6 +3465,17 @@ const seed = async (database) => {
3374
3465
  }
3375
3466
  });
3376
3467
  await core.markNativeBuild(createBundleFixture("8011").id, { storeBuild: true });
3468
+ const pendingDevice = (await core.requestIosDevice({
3469
+ udid: BUDGET_PENDING_UDID,
3470
+ name: "Pending iPhone",
3471
+ requestedBy: "kim@team.dev"
3472
+ })).device;
3473
+ const { device: requestedDevice } = await core.requestIosDevice({
3474
+ udid: BUDGET_APPROVED_UDID,
3475
+ name: "Approved iPhone",
3476
+ requestedBy: "kim@team.dev"
3477
+ });
3478
+ const approvedDevice = await core.approveIosDevice(requestedDevice.id, { approvedBy: "lead@team.dev" });
3377
3479
  const { apiKey } = await api.apiKeys.create({ name: "Read budgets" });
3378
3480
  for (let n = 1; n <= 24; n += 1) await api.insights.recordEvent(eventOf(n));
3379
3481
  await api.insights.recordEvent(eventOf(25, {
@@ -3411,6 +3513,8 @@ const seed = async (database) => {
3411
3513
  apiKey,
3412
3514
  productionId,
3413
3515
  nightlyId: (await channel("nightly")).id,
3516
+ pendingDevice,
3517
+ approvedDevice,
3414
3518
  /** The auto-patch base key of a new production iOS 1.0.0 bundle. */
3415
3519
  candidateKey: targetBaseCandidateKey({
3416
3520
  channel: "production",
@@ -3421,6 +3525,8 @@ const seed = async (database) => {
3421
3525
  };
3422
3526
  };
3423
3527
  const budget = (entry) => entry;
3528
+ const BUDGET_PENDING_UDID = "00008030-000000000000000a";
3529
+ const BUDGET_APPROVED_UDID = "00008030-000000000000000b";
3424
3530
  const reads = (gets, keys, queries, rows) => ({
3425
3531
  gets,
3426
3532
  keys,
@@ -4034,6 +4140,126 @@ const READ_BUDGETS = [
4034
4140
  nativeBuild: { min_bundle_id: createBundleFixture("011").id }
4035
4141
  })
4036
4142
  }),
4143
+ budget({
4144
+ api: "iOS devices by status: 1 query, the rows used",
4145
+ read: ({ core }) => core.listIosDevices({
4146
+ status: "approved",
4147
+ limit: 50
4148
+ }),
4149
+ adapter: reads(0, 0, 1, 1),
4150
+ engine: {
4151
+ calls: 1,
4152
+ rows: 1
4153
+ },
4154
+ returned: (rows) => rows.length,
4155
+ check: (rows) => expect(rows.map((row) => row.udid)).toEqual([BUDGET_APPROVED_UDID])
4156
+ }),
4157
+ budget({
4158
+ api: "iOS device by UDID: 1 unique read",
4159
+ read: ({ core }) => core.findIosDevice(BUDGET_PENDING_UDID.toUpperCase()),
4160
+ adapter: reads(0, 0, 1, 1),
4161
+ engine: {
4162
+ calls: 1,
4163
+ rows: 1
4164
+ },
4165
+ check: (device) => expect(device?.status).toBe("pending")
4166
+ }),
4167
+ budget({
4168
+ api: "iOS device request: the UDID's read and 1 write",
4169
+ read: ({ core }) => core.requestIosDevice({
4170
+ udid: "00008030-000000000000000c",
4171
+ name: "New iPhone",
4172
+ requestedBy: null
4173
+ }),
4174
+ adapter: reads(0, 0, 1, 0),
4175
+ engine: {
4176
+ calls: 1,
4177
+ rows: 0
4178
+ },
4179
+ writes: 1,
4180
+ check: (result) => expect(result.created).toBe(true)
4181
+ }),
4182
+ budget({
4183
+ api: "iOS device approval: the row and 1 write",
4184
+ read: ({ core, pendingDevice }) => core.approveIosDevice(pendingDevice.id, { approvedBy: null }),
4185
+ adapter: reads(1, 1, 0, 0),
4186
+ engine: {
4187
+ calls: 1,
4188
+ rows: 1
4189
+ },
4190
+ writes: 1,
4191
+ check: (device) => expect(device?.status).toBe("approved")
4192
+ }),
4193
+ budget({
4194
+ api: "iOS device outcome: the row and 1 write",
4195
+ read: ({ core, approvedDevice }) => core.recordIosDeviceOutcome({
4196
+ id: approvedDevice.id,
4197
+ seen: {
4198
+ status: "approved",
4199
+ approvedAtMs: approvedDevice.approved_at_ms
4200
+ },
4201
+ issuerId: "issuer-a",
4202
+ outcome: "registered"
4203
+ }),
4204
+ adapter: reads(1, 1, 0, 0),
4205
+ engine: {
4206
+ calls: 1,
4207
+ rows: 1
4208
+ },
4209
+ writes: 1,
4210
+ check: (device) => expect(device?.status).toBe("registered")
4211
+ }),
4212
+ budget({
4213
+ api: "iOS devices in a build: the row and 1 write each",
4214
+ read: ({ core, approvedDevice }) => core.markIosDevicesInBuild({
4215
+ buildId: createBundleFixture("8012").id,
4216
+ ids: [approvedDevice.id]
4217
+ }),
4218
+ adapter: reads(1, 1, 0, 0),
4219
+ engine: {
4220
+ calls: 1,
4221
+ rows: 1
4222
+ },
4223
+ writes: 1
4224
+ }),
4225
+ budget({
4226
+ api: "iOS device delete: the row and 1 write",
4227
+ read: ({ core, pendingDevice }) => core.deleteIosDevice(pendingDevice.id),
4228
+ adapter: reads(1, 1, 0, 0),
4229
+ engine: {
4230
+ calls: 1,
4231
+ rows: 1
4232
+ },
4233
+ writes: 1,
4234
+ check: (device) => expect(device?.udid).toBe(BUDGET_PENDING_UDID)
4235
+ }),
4236
+ budget({
4237
+ api: "iOS device account, first claim: its one row's read, the registry's rows once, and 1 write",
4238
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-a"),
4239
+ adapter: reads(1, 1, 1, 2),
4240
+ engine: {
4241
+ calls: 2,
4242
+ rows: 2
4243
+ },
4244
+ writes: 1,
4245
+ check: (claim) => expect(claim).toEqual({
4246
+ issuerId: "issuer-a",
4247
+ claimed: true
4248
+ })
4249
+ }),
4250
+ budget({
4251
+ api: "iOS device account, claimed: its one row's read",
4252
+ read: ({ core }) => core.claimIosDeviceAccount("issuer-b"),
4253
+ adapter: reads(1, 1, 0, 0),
4254
+ engine: {
4255
+ calls: 1,
4256
+ rows: 1
4257
+ },
4258
+ check: (claim) => expect(claim).toEqual({
4259
+ issuerId: "issuer-a",
4260
+ claimed: false
4261
+ })
4262
+ }),
4037
4263
  budget({
4038
4264
  api: "record an insights event: 2 dependent rounds of batch gets and 1 write",
4039
4265
  read: ({ insights }) => insights.recordEvent(eventOf(27, {