From 40926e393f0bc0bfeb87d5576cbe97c74b8a65c6 Mon Sep 17 00:00:00 2001 From: rjbrache Date: Fri, 13 Oct 2023 09:21:58 -0700 Subject: [PATCH] fix: Remove data from Mongo on deactivation (#1118) --- src/data/mongo/collections/device.test.ts | 6 +++--- src/data/mongo/collections/device.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/data/mongo/collections/device.test.ts b/src/data/mongo/collections/device.test.ts index 1e516ae15..5891eec94 100644 --- a/src/data/mongo/collections/device.test.ts +++ b/src/data/mongo/collections/device.test.ts @@ -64,13 +64,13 @@ describe('MongoDeviceTable', () => { expect(collection.findOne).toHaveBeenCalledWith({ guid: 'someId', tenantId: 'someTenantId' }) }) - it('should delete document by name and tenantId', async () => { + it('should delete document by guid and tenantId', async () => { collection.deleteOne.mockResolvedValue({ deletedCount: 1 } as any) - const result = await mongoDeviceTable.delete('someName', 'someTenantId') + const result = await mongoDeviceTable.delete('someGuid', 'someTenantId') expect(result).toBe(true) - expect(collection.deleteOne).toHaveBeenCalledWith({ friendlyName: 'someName', tenantId: 'someTenantId' }) + expect(collection.deleteOne).toHaveBeenCalledWith({ guid: 'someGuid', tenantId: 'someTenantId' }) }) it('should insert a device', async () => { diff --git a/src/data/mongo/collections/device.ts b/src/data/mongo/collections/device.ts index 8374fb2f4..40c3b3d26 100644 --- a/src/data/mongo/collections/device.ts +++ b/src/data/mongo/collections/device.ts @@ -33,8 +33,8 @@ export class MongoDeviceTable implements IDeviceTable { return this.collection.findOne({ guid: id, tenantId }) as unknown as WithId } - async delete (name: string, tenantId: string = ''): Promise { - const result = await this.collection.deleteOne({ friendlyName: name, tenantId }) + async delete (id: string, tenantId: string = ''): Promise { + const result = await this.collection.deleteOne({ guid: id, tenantId }) return result.deletedCount && result.deletedCount > 0 }