Skip to content

Commit e8e0c0b

Browse files
authored
test(NODE-4993): migrate create a data key test to promise usage (#539)
1 parent 50d4d4f commit e8e0c0b

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

bindings/node/test/clientEncryption.test.js

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,24 @@ describe('ClientEncryption', function () {
202202
options: { masterKey: { region: 'region', key: 'cmk' } }
203203
}
204204
].forEach(providerTest => {
205-
it(`should create a data key with the "${providerTest.name}" KMS provider`, function (done) {
205+
it(`should create a data key with the "${providerTest.name}" KMS provider`, async function () {
206206
const providerName = providerTest.name;
207207
const encryption = new ClientEncryption(client, {
208208
keyVaultNamespace: 'client.encryption',
209209
kmsProviders: providerTest.kmsProviders
210210
});
211211

212212
const dataKeyOptions = providerTest.options || {};
213-
encryption.createDataKey(providerName, dataKeyOptions, (err, dataKey) => {
214-
expect(err).to.not.exist;
215-
expect(dataKey._bsontype).to.equal('Binary');
216-
217-
client
218-
.db('client')
219-
.collection('encryption')
220-
.findOne({ _id: dataKey }, (err, doc) => {
221-
expect(err).to.not.exist;
222-
expect(doc).to.have.property('masterKey');
223-
expect(doc.masterKey).to.have.property('provider');
224-
expect(doc.masterKey.provider).to.eql(providerName);
225-
done();
226-
});
227-
});
213+
214+
const dataKey = await encryption.createDataKey(providerName, dataKeyOptions);
215+
expect(dataKey).property('_bsontype', 'Binary');
216+
217+
const doc = await client.db('client').collection('encryption').findOne({ _id: dataKey });
218+
expect(doc).to.have.property('masterKey');
219+
expect(doc.masterKey).property('provider', providerName);
228220
});
229221

230-
it(`should create a data key with the "${providerTest.name}" KMS provider (fixed key material)`, function (done) {
222+
it(`should create a data key with the "${providerTest.name}" KMS provider (fixed key material)`, async function () {
231223
const providerName = providerTest.name;
232224
const encryption = new ClientEncryption(client, {
233225
keyVaultNamespace: 'client.encryption',
@@ -238,21 +230,13 @@ describe('ClientEncryption', function () {
238230
...providerTest.options,
239231
keyMaterial: new BSON.Binary(Buffer.alloc(96))
240232
};
241-
encryption.createDataKey(providerName, dataKeyOptions, (err, dataKey) => {
242-
expect(err).to.not.exist;
243-
expect(dataKey._bsontype).to.equal('Binary');
244-
245-
client
246-
.db('client')
247-
.collection('encryption')
248-
.findOne({ _id: dataKey }, (err, doc) => {
249-
expect(err).to.not.exist;
250-
expect(doc).to.have.property('masterKey');
251-
expect(doc.masterKey).to.have.property('provider');
252-
expect(doc.masterKey.provider).to.eql(providerName);
253-
done();
254-
});
255-
});
233+
234+
const dataKey = await encryption.createDataKey(providerName, dataKeyOptions);
235+
expect(dataKey).property('_bsontype', 'Binary');
236+
237+
const doc = await client.db('client').collection('encryption').findOne({ _id: dataKey });
238+
expect(doc).to.have.property('masterKey');
239+
expect(doc.masterKey).property('provider', providerName);
256240
});
257241
});
258242

0 commit comments

Comments
 (0)