|
1 | | -import {getBulkOperationStatus, listBulkOperations} from './bulk-operation-status.js' |
| 1 | +import { |
| 2 | + getBulkOperationStatus, |
| 3 | + listBulkOperations, |
| 4 | + normalizeBulkOperationId, |
| 5 | + extractBulkOperationId, |
| 6 | +} from './bulk-operation-status.js' |
2 | 7 | import {GetBulkOperationByIdQuery} from '../../api/graphql/bulk-operations/generated/get-bulk-operation-by-id.js' |
3 | 8 | import {OrganizationApp, Organization, OrganizationSource} from '../../models/organization.js' |
4 | 9 | import {ListBulkOperationsQuery} from '../../api/graphql/bulk-operations/generated/list-bulk-operations.js' |
@@ -36,6 +41,37 @@ afterEach(() => { |
36 | 41 | mockAndCaptureOutput().clear() |
37 | 42 | }) |
38 | 43 |
|
| 44 | +describe('normalizeBulkOperationId', () => { |
| 45 | + test('returns GID as-is when already in GID format', () => { |
| 46 | + const gid = 'gid://shopify/BulkOperation/123' |
| 47 | + expect(normalizeBulkOperationId(gid)).toBe(gid) |
| 48 | + }) |
| 49 | + |
| 50 | + test('converts numeric ID to GID format', () => { |
| 51 | + expect(normalizeBulkOperationId('123')).toBe('gid://shopify/BulkOperation/123') |
| 52 | + expect(normalizeBulkOperationId('456789')).toBe('gid://shopify/BulkOperation/456789') |
| 53 | + }) |
| 54 | + |
| 55 | + test('returns non-numeric, non-GID string as-is', () => { |
| 56 | + const invalidId = 'invalid-id' |
| 57 | + expect(normalizeBulkOperationId(invalidId)).toBe(invalidId) |
| 58 | + }) |
| 59 | +}) |
| 60 | + |
| 61 | +describe('extractBulkOperationId', () => { |
| 62 | + test('extracts numeric ID from GID', () => { |
| 63 | + expect(extractBulkOperationId('gid://shopify/BulkOperation/123')).toBe('123') |
| 64 | + expect(extractBulkOperationId('gid://shopify/BulkOperation/456789')).toBe('456789') |
| 65 | + }) |
| 66 | + |
| 67 | + test('returns input as-is if not a valid GID format', () => { |
| 68 | + expect(extractBulkOperationId('gid://shopify/BulkOperation/ABC')).toBe('gid://shopify/BulkOperation/ABC') |
| 69 | + expect(extractBulkOperationId('BulkOperation/123')).toBe('BulkOperation/123') |
| 70 | + expect(extractBulkOperationId('invalid-id')).toBe('invalid-id') |
| 71 | + expect(extractBulkOperationId('123')).toBe('123') |
| 72 | + }) |
| 73 | +}) |
| 74 | + |
39 | 75 | describe('getBulkOperationStatus', () => { |
40 | 76 | function mockBulkOperation( |
41 | 77 | overrides?: Partial<NonNullable<GetBulkOperationByIdQuery['bulkOperation']>>, |
@@ -222,15 +258,15 @@ describe('listBulkOperations', () => { |
222 | 258 | │ │ |
223 | 259 | ╰──────────────────────────────────────────────────────────────────────────────╯ |
224 | 260 |
|
225 | | - ID STATUS COU DATE CREATED DATE RESULTS |
226 | | - T FINISHED |
| 261 | + I STATUS COUNT DATE CREATED DATE FINISHED RESULTS |
227 | 262 |
|
228 | | - ──────────────── ────── ─── ──────────── ─────────── ─────────────────────────── |
229 | | - ──────────── ── ── ─────── ─────── ─────────────────── |
230 | | - gid://shopify/Bu COMPLE 123 2025-11-10 2025-11-10 download ( https://example. |
231 | | - kOperation/1 ED 5K 12:37:52 16:37:12 com/results.jsonl ) |
232 | | - gid://shopify/Bu RUNNIN 100 2025-11-11 |
233 | | - kOperation/2 15:37:52" |
| 263 | + ─ ─────── ───── ────────────── ────────────── ────────────────────────────────── |
| 264 | + ─ ──── ──── ──────────── |
| 265 | + 1 COMPLET 123.5 2025-11-10 2025-11-10 download ( |
| 266 | + D 12:37:52 16:37:12 https://example.com/results.jsonl |
| 267 | + ) |
| 268 | + 2 RUNNING 100 2025-11-11 |
| 269 | + 15:37:52" |
234 | 270 | `) |
235 | 271 | }) |
236 | 272 |
|
|
0 commit comments