plugin-file-preview-auth 1.3.10 → 1.3.11

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.
@@ -1,103 +1,103 @@
1
- import {
2
- extractOcrStatusRecord,
3
- getOcrAttachmentId,
4
- isOcrCapableCollection,
5
- isOcrCompleteStatus,
6
- normalizeOcrAttachmentId,
7
- } from '../index';
8
-
9
- describe('file preview OCR client utils', () => {
10
- describe('normalizeOcrAttachmentId', () => {
11
- it('accepts numeric attachment ids', () => {
12
- expect(normalizeOcrAttachmentId(12)).toBe(12);
13
- expect(normalizeOcrAttachmentId('12')).toBe('12');
14
- expect(normalizeOcrAttachmentId(' 12 ')).toBe('12');
15
- });
16
-
17
- it('rejects URLs and upload-only ids', () => {
18
- expect(normalizeOcrAttachmentId('http://localhost/storage/uploads/test.pdf')).toBeNull();
19
- expect(normalizeOcrAttachmentId('/storage/uploads/test.pdf')).toBeNull();
20
- expect(normalizeOcrAttachmentId('rc-upload-1710000000000-1')).toBeNull();
21
- });
22
- });
23
-
24
- describe('getOcrAttachmentId', () => {
25
- it('uses response.id when file.id is a storage URL', () => {
26
- expect(
27
- getOcrAttachmentId({
28
- id: 'http://localhost/storage/uploads/yyyy-test%20(1)-lcqadd.pdf',
29
- uid: 'rc-upload-1',
30
- response: {
31
- id: 42,
32
- },
33
- }),
34
- ).toBe(42);
35
- });
36
-
37
- it('falls back to a numeric uid for persisted attachment records', () => {
38
- expect(
39
- getOcrAttachmentId({
40
- id: '/storage/uploads/yyyy-test.pdf',
41
- uid: '88',
42
- }),
43
- ).toBe('88');
44
- });
45
- });
46
-
47
- describe('isOcrCapableCollection', () => {
48
- it('allows attachments and collection-less records', () => {
49
- expect(isOcrCapableCollection({ id: 1 })).toBe(true);
50
- expect(isOcrCapableCollection({ id: 1, collectionName: 'attachments' })).toBe(true);
51
- expect(isOcrCapableCollection({ id: 1, collectionName: '' })).toBe(true);
52
- });
53
-
54
- it('rejects non-attachment collections like aiFiles', () => {
55
- expect(isOcrCapableCollection({ id: 1, collectionName: 'aiFiles' })).toBe(false);
56
- });
57
- });
58
-
59
- describe('isOcrCompleteStatus', () => {
60
- it('only treats result statuses as completed', () => {
61
- expect(isOcrCompleteStatus('waiting-verify')).toBe(true);
62
- expect(isOcrCompleteStatus('success')).toBe(true);
63
- expect(isOcrCompleteStatus('no-ocr')).toBe(false);
64
- expect(isOcrCompleteStatus('pending-ocr')).toBe(false);
65
- expect(isOcrCompleteStatus('failed')).toBe(false);
66
- });
67
- });
68
-
69
- describe('extractOcrStatusRecord', () => {
70
- it('unwraps NocoBase double data responses', () => {
71
- const record = extractOcrStatusRecord({
72
- data: {
73
- data: {
74
- id: 4,
75
- attachmentId: 57,
76
- status: 'waiting-verify',
77
- data: { pages: [] },
78
- error: null,
79
- },
80
- },
81
- });
82
-
83
- expect(record?.id).toBe(4);
84
- expect(record?.attachmentId).toBe(57);
85
- expect(record?.status).toBe('waiting-verify');
86
- });
87
-
88
- it('unwraps action responses with ok and data', () => {
89
- const record = extractOcrStatusRecord({
90
- data: {
91
- ok: true,
92
- data: {
93
- id: 5,
94
- status: 'pending-ocr',
95
- },
96
- },
97
- });
98
-
99
- expect(record?.id).toBe(5);
100
- expect(record?.status).toBe('pending-ocr');
101
- });
102
- });
103
- });
1
+ import {
2
+ extractOcrStatusRecord,
3
+ getOcrAttachmentId,
4
+ isOcrCapableCollection,
5
+ isOcrCompleteStatus,
6
+ normalizeOcrAttachmentId,
7
+ } from '../index';
8
+
9
+ describe('file preview OCR client utils', () => {
10
+ describe('normalizeOcrAttachmentId', () => {
11
+ it('accepts numeric attachment ids', () => {
12
+ expect(normalizeOcrAttachmentId(12)).toBe(12);
13
+ expect(normalizeOcrAttachmentId('12')).toBe('12');
14
+ expect(normalizeOcrAttachmentId(' 12 ')).toBe('12');
15
+ });
16
+
17
+ it('rejects URLs and upload-only ids', () => {
18
+ expect(normalizeOcrAttachmentId('http://localhost/storage/uploads/test.pdf')).toBeNull();
19
+ expect(normalizeOcrAttachmentId('/storage/uploads/test.pdf')).toBeNull();
20
+ expect(normalizeOcrAttachmentId('rc-upload-1710000000000-1')).toBeNull();
21
+ });
22
+ });
23
+
24
+ describe('getOcrAttachmentId', () => {
25
+ it('uses response.id when file.id is a storage URL', () => {
26
+ expect(
27
+ getOcrAttachmentId({
28
+ id: 'http://localhost/storage/uploads/yyyy-test%20(1)-lcqadd.pdf',
29
+ uid: 'rc-upload-1',
30
+ response: {
31
+ id: 42,
32
+ },
33
+ }),
34
+ ).toBe(42);
35
+ });
36
+
37
+ it('falls back to a numeric uid for persisted attachment records', () => {
38
+ expect(
39
+ getOcrAttachmentId({
40
+ id: '/storage/uploads/yyyy-test.pdf',
41
+ uid: '88',
42
+ }),
43
+ ).toBe('88');
44
+ });
45
+ });
46
+
47
+ describe('isOcrCapableCollection', () => {
48
+ it('allows attachments and collection-less records', () => {
49
+ expect(isOcrCapableCollection({ id: 1 })).toBe(true);
50
+ expect(isOcrCapableCollection({ id: 1, collectionName: 'attachments' })).toBe(true);
51
+ expect(isOcrCapableCollection({ id: 1, collectionName: '' })).toBe(true);
52
+ });
53
+
54
+ it('rejects non-attachment collections like aiFiles', () => {
55
+ expect(isOcrCapableCollection({ id: 1, collectionName: 'aiFiles' })).toBe(false);
56
+ });
57
+ });
58
+
59
+ describe('isOcrCompleteStatus', () => {
60
+ it('only treats result statuses as completed', () => {
61
+ expect(isOcrCompleteStatus('waiting-verify')).toBe(true);
62
+ expect(isOcrCompleteStatus('success')).toBe(true);
63
+ expect(isOcrCompleteStatus('no-ocr')).toBe(false);
64
+ expect(isOcrCompleteStatus('pending-ocr')).toBe(false);
65
+ expect(isOcrCompleteStatus('failed')).toBe(false);
66
+ });
67
+ });
68
+
69
+ describe('extractOcrStatusRecord', () => {
70
+ it('unwraps NocoBase double data responses', () => {
71
+ const record = extractOcrStatusRecord({
72
+ data: {
73
+ data: {
74
+ id: 4,
75
+ attachmentId: 57,
76
+ status: 'waiting-verify',
77
+ data: { pages: [] },
78
+ error: null,
79
+ },
80
+ },
81
+ });
82
+
83
+ expect(record?.id).toBe(4);
84
+ expect(record?.attachmentId).toBe(57);
85
+ expect(record?.status).toBe('waiting-verify');
86
+ });
87
+
88
+ it('unwraps action responses with ok and data', () => {
89
+ const record = extractOcrStatusRecord({
90
+ data: {
91
+ ok: true,
92
+ data: {
93
+ id: 5,
94
+ status: 'pending-ocr',
95
+ },
96
+ },
97
+ });
98
+
99
+ expect(record?.id).toBe(5);
100
+ expect(record?.status).toBe('pending-ocr');
101
+ });
102
+ });
103
+ });