Skip to content

Commit 888c0a8

Browse files
Remove table testing in favor of hard-coded it blocks
1 parent 53d31a6 commit 888c0a8

File tree

1 file changed

+100
-116
lines changed

1 file changed

+100
-116
lines changed

test/encryptedSchema.test.js

Lines changed: 100 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -61,135 +61,119 @@ describe('encrypted schema declaration', function() {
6161
});
6262

6363
describe('Tests that fields of valid schema types can be declared as encrypted schemas', function() {
64-
const tests = {
65-
'nested schema for csfle':
66-
{
67-
schemaFactory: () => {
68-
const encryptedSchema = new Schema({
69-
encrypted: {
70-
type: String, encrypt: { keyId: KEY_ID, algorithm }
71-
}
72-
}, { encryptionType: 'csfle' });
73-
return new Schema({
74-
field: encryptedSchema
75-
}, { encryptionType: 'csfle' });
76-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted'])),
77-
schemaMap: {
78-
bsonType: 'object',
79-
properties: {
80-
field: {
81-
bsonType: 'object',
82-
properties: {
83-
encrypted: { encrypt: { bsonType: 'string', algorithm, keyId: KEY_ID } }
84-
}
64+
it('nested schema for csfle', function() {
65+
const encryptedSchema = new Schema({
66+
encrypted: {
67+
type: String, encrypt: { keyId: KEY_ID, algorithm }
68+
}
69+
}, { encryptionType: 'csfle' });
70+
const schema = new Schema({
71+
field: encryptedSchema
72+
}, { encryptionType: 'csfle' });
73+
74+
assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted']));
75+
76+
assert.deepEqual(schema._buildSchemaMap(), {
77+
bsonType: 'object',
78+
properties: {
79+
field: {
80+
bsonType: 'object',
81+
properties: {
82+
encrypted: { encrypt: { bsonType: 'string', algorithm, keyId: KEY_ID } }
8583
}
8684
}
8785
}
88-
},
89-
'nested schema for qe': {
90-
schemaFactory: () => {
91-
const encryptedSchema = new Schema({
92-
encrypted: {
93-
type: String, encrypt: { keyId: KEY_ID }
94-
}
95-
}, { encryptionType: 'qe' });
96-
return new Schema({
97-
field: encryptedSchema
98-
}, { encryptionType: 'qe' });
99-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted'])),
100-
encryptedFields: {
101-
fields: [
102-
{ path: 'field.encrypted', keyId: KEY_ID, bsonType: 'string' }
103-
]
86+
});
87+
});
88+
it('nested schema for qe', function() {
89+
const encryptedSchema = new Schema({
90+
encrypted: {
91+
type: String, encrypt: { keyId: KEY_ID }
10492
}
105-
},
106-
'nested object for csfle':
107-
{
108-
schemaFactory: () => {
109-
return new Schema({
110-
field: {
111-
encrypted: {
112-
type: String, encrypt: { keyId: KEY_ID, algorithm }
113-
}
114-
}
115-
}, { encryptionType: 'csfle' });
116-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted'])),
117-
schemaMap: {
118-
bsonType: 'object',
119-
properties: {
120-
field: {
121-
bsonType: 'object',
122-
properties: {
123-
encrypted: { encrypt: { bsonType: 'string', algorithm, keyId: KEY_ID } }
124-
}
125-
}
93+
}, { encryptionType: 'qe' });
94+
const schema = new Schema({
95+
field: encryptedSchema
96+
}, { encryptionType: 'qe' });
97+
assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted']));
98+
99+
assert.deepEqual(schema._buildEncryptedFields(), {
100+
fields: [
101+
{ path: 'field.encrypted', keyId: KEY_ID, bsonType: 'string' }
102+
]
103+
});
104+
});
105+
it('nested object for csfle', function() {
106+
const schema = new Schema({
107+
field: {
108+
encrypted: {
109+
type: String, encrypt: { keyId: KEY_ID, algorithm }
126110
}
127111
}
128-
},
129-
'nested object for qe': {
130-
schemaFactory: () => {
131-
return new Schema({
132-
field: {
133-
encrypted: {
134-
type: String, encrypt: { keyId: KEY_ID }
135-
}
112+
}, { encryptionType: 'csfle' });
113+
assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted']));
114+
assert.deepEqual(schema._buildSchemaMap(), {
115+
bsonType: 'object',
116+
properties: {
117+
field: {
118+
bsonType: 'object',
119+
properties: {
120+
encrypted: { encrypt: { bsonType: 'string', algorithm, keyId: KEY_ID } }
136121
}
137-
}, { encryptionType: 'qe' });
138-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted'])),
139-
encryptedFields: {
140-
fields: [
141-
{ path: 'field.encrypted', keyId: KEY_ID, bsonType: 'string' }
142-
]
122+
}
143123
}
144-
},
145-
'schema with encrypted array for csfle': {
146-
schemaFactory: () => {
147-
return new Schema({
148-
encrypted: {
149-
type: [Number],
150-
encrypt: { keyId: KEY_ID, algorithm }
151-
}
152-
}, { encryptionType: 'csfle' });
153-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['encrypted'])),
154-
schemaMap: {
155-
bsonType: 'object',
156-
properties: {
157-
encrypted: {
158-
encrypt: {
159-
bsonType: 'array',
160-
keyId: KEY_ID,
161-
algorithm
162-
}
163-
}
124+
});
125+
});
126+
it('nested object for qe', function() {
127+
const schema = new Schema({
128+
field: {
129+
encrypted: {
130+
type: String, encrypt: { keyId: KEY_ID }
164131
}
165132
}
166-
},
167-
'schema with encrypted array for qe': {
168-
schemaFactory: () => {
169-
return new Schema({
170-
encrypted: {
171-
type: [Number],
172-
encrypt: { keyId: KEY_ID }
173-
}
174-
}, { encryptionType: 'qe' });
175-
}, predicate: (schema) => assert.ok(schemaHasEncryptedProperty(schema, ['encrypted'])),
176-
encryptedFields: {
177-
fields: [
178-
{ path: 'encrypted', keyId: KEY_ID, bsonType: 'array' }
179-
]
133+
}, { encryptionType: 'qe' });
134+
assert.ok(schemaHasEncryptedProperty(schema, ['field', 'encrypted']));
135+
assert.deepEqual(schema._buildEncryptedFields(), {
136+
fields: [
137+
{ path: 'field.encrypted', keyId: KEY_ID, bsonType: 'string' }
138+
]
139+
});
140+
});
141+
it('schema with encrypted array for csfle', function() {
142+
const schema = new Schema({
143+
encrypted: {
144+
type: [Number],
145+
encrypt: { keyId: KEY_ID, algorithm }
180146
}
181-
}
182-
};
183-
184-
for (const [description, { schemaFactory, predicate, schemaMap, encryptedFields }] of Object.entries(tests)) {
185-
it(description, function() {
186-
const schema = schemaFactory();
187-
predicate(schema);
147+
}, { encryptionType: 'csfle' });
148+
assert.ok(schemaHasEncryptedProperty(schema, ['encrypted']));
188149

189-
schemaMap && assert.deepEqual(schema._buildSchemaMap(), schemaMap);
190-
encryptedFields && assert.deepEqual(schema._buildEncryptedFields(), encryptedFields);
150+
assert.deepEqual(schema._buildSchemaMap(), {
151+
bsonType: 'object',
152+
properties: {
153+
encrypted: {
154+
encrypt: {
155+
bsonType: 'array',
156+
keyId: KEY_ID,
157+
algorithm
158+
}
159+
}
160+
}
191161
});
192-
}
162+
});
163+
it('schema with encrypted array for qe', function() {
164+
const schema = new Schema({
165+
encrypted: {
166+
type: [Number],
167+
encrypt: { keyId: KEY_ID }
168+
}
169+
}, { encryptionType: 'qe' });
170+
assert.ok(schemaHasEncryptedProperty(schema, ['encrypted']));
171+
assert.deepEqual(schema._buildEncryptedFields(), {
172+
fields: [
173+
{ path: 'encrypted', keyId: KEY_ID, bsonType: 'array' }
174+
]
175+
});
176+
});
193177
});
194178

195179
describe('invalid schema types for encrypted schemas', function() {

0 commit comments

Comments
 (0)