@mlagie/sql-connector 2.0.5 → 2.0.7

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.
@@ -38,4 +38,204 @@ describe('Utils - generateCondition.js', () => {
38
38
  const filter = { name: '"Alice"' };
39
39
  expect(generateCondition(filter, false)).toBe("`name` = 'Alice'");
40
40
  });
41
+
42
+ test("generateCondition utilise les champs unique du schema", () => {
43
+ const result = generateCondition(
44
+ { email: "john@test.fr" },
45
+ false,
46
+ {
47
+ schemaDict: {
48
+ email: {
49
+ unique: true
50
+ }
51
+ }
52
+ }
53
+ );
54
+
55
+ expect(result).toContain("email");
56
+ });
57
+
58
+ test("generateCondition génère un IN pour les champs uniques tableau", () => {
59
+ const result = generateCondition(
60
+ { email: ["a@test.fr", "b@test.fr"] },
61
+ false,
62
+ {
63
+ schemaDict: {
64
+ email: {
65
+ unique: true
66
+ }
67
+ }
68
+ }
69
+ );
70
+
71
+ expect(result).toContain("IN");
72
+ });
73
+
74
+ test("generateCondition génère un JSON_CONTAINS pour objet unique", () => {
75
+ const result = generateCondition(
76
+ {
77
+ metadata: {
78
+ role: "admin"
79
+ }
80
+ },
81
+ false,
82
+ {
83
+ schemaDict: {
84
+ metadata: {
85
+ unique: true
86
+ }
87
+ }
88
+ }
89
+ );
90
+
91
+ expect(result).toContain("JSON_CONTAINS");
92
+ });
93
+
94
+ test("generateCondition génère IS NULL pour champ unique", () => {
95
+ const result = generateCondition(
96
+ { email: null },
97
+ false,
98
+ {
99
+ schemaDict: {
100
+ email: {
101
+ unique: true
102
+ }
103
+ }
104
+ }
105
+ );
106
+
107
+ expect(result).toContain("IS NULL");
108
+ });
109
+
110
+ test("generateCondition convertit une date ISO sur champ unique", () => {
111
+ const result = generateCondition(
112
+ {
113
+ created_at: "2025-01-01T10:00:00Z"
114
+ },
115
+ false,
116
+ {
117
+ schemaDict: {
118
+ created_at: {
119
+ unique: true
120
+ }
121
+ }
122
+ }
123
+ );
124
+
125
+ expect(result).toContain("2025-01-01 10:00:00");
126
+ });
127
+
128
+ test("generateCondition update JSON", () => {
129
+ const result = generateCondition(
130
+ {
131
+ metadata: {
132
+ role: "admin"
133
+ }
134
+ },
135
+ true
136
+ );
137
+
138
+ expect(result).toContain("=");
139
+ expect(result).not.toContain("JSON_CONTAINS");
140
+ });
141
+
142
+ test("generateCondition filtre JSON", () => {
143
+ const result = generateCondition(
144
+ {
145
+ metadata: {
146
+ role: "admin"
147
+ }
148
+ },
149
+ false
150
+ );
151
+
152
+ expect(result).toContain("JSON_CONTAINS");
153
+ });
154
+
155
+ test("generateCondition retourne une condition simple", () => {
156
+ const result = generateCondition(
157
+ { id: 42 },
158
+ false
159
+ );
160
+
161
+ expect(result).toContain("42");
162
+ });
163
+
164
+ test("generateCondition retire les guillemets doubles entourant une valeur", () => {
165
+ const result = generateCondition(
166
+ { name: '"john"' },
167
+ false,
168
+ {
169
+ schemaDict: {
170
+ name: {
171
+ unique: true
172
+ }
173
+ }
174
+ }
175
+ );
176
+
177
+ expect(result).toContain("john");
178
+ expect(result).not.toContain('"john"');
179
+ });
180
+
181
+ test("generateCondition utilise JSON_CONTAINS avec une chaîne JSON", () => {
182
+ const result = generateCondition(
183
+ {
184
+ metadata: '{"role":"admin"}'
185
+ },
186
+ false,
187
+ {
188
+ schemaDict: {
189
+ metadata: {
190
+ unique: true
191
+ }
192
+ }
193
+ }
194
+ );
195
+
196
+ expect(result).toContain("JSON_CONTAINS");
197
+ });
198
+
199
+ test("generateCondition détecte une chaîne JSON", () => {
200
+ const result = generateCondition({
201
+ metadata: '{"role":"admin"}'
202
+ });
203
+
204
+ expect(result).toContain("JSON_CONTAINS");
205
+ });
206
+
207
+ test("generateCondition supporte fieldDef.type string", () => {
208
+ generateCondition(
209
+ {
210
+ created_at: "2025-01-01T10:00:00Z"
211
+ },
212
+ false,
213
+ {
214
+ schemaDict: {
215
+ created_at: {
216
+ type: "Date"
217
+ }
218
+ }
219
+ }
220
+ );
221
+ });
222
+
223
+ test("generateCondition convertit une date ISO pour un champ Date", () => {
224
+ const result = generateCondition(
225
+ {
226
+ created_at: "2025-01-01T10:00:00Z"
227
+ },
228
+ false,
229
+ {
230
+ schemaDict: {
231
+ created_at: {
232
+ type: Date
233
+ }
234
+ }
235
+ }
236
+ );
237
+
238
+ expect(result).toContain("2025-01-01 10:00:00");
239
+ });
240
+
41
241
  });