-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
58f555e
commit aba855b
Showing
22 changed files
with
655 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,70 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CwDeviceOwnersController } from './cw_device_owners.controller'; | ||
import { CwDeviceOwnersService } from './cw_device_owners.service'; | ||
import { DevicesOwnersRow } from 'src/common/database-types'; | ||
import { CreateDeviceOwnerDto } from './dto/create-device-owner.dto'; | ||
import { UpdateDeviceOwnerDto } from './dto/update-device-owner.dto'; | ||
|
||
describe('CwDeviceOwnersController', () => { | ||
let controller: CwDeviceOwnersController; | ||
let service: CwDeviceOwnersService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [CwDeviceOwnersController], | ||
providers: [ | ||
{ | ||
provide: CwDeviceOwnersService, | ||
useValue: { | ||
findAll: jest.fn().mockResolvedValue([]), | ||
create: jest.fn().mockResolvedValue({ id: 1, owner_id: 'test-owner' }), | ||
fullUpdate: jest.fn().mockResolvedValue({ id: 1, owner_id: 'updated-owner' }), | ||
partialUpdate: jest.fn().mockResolvedValue({ id: 1, owner_id: 'partially-updated-owner' }), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get<CwDeviceOwnersController>(CwDeviceOwnersController); | ||
service = module.get<CwDeviceOwnersService>(CwDeviceOwnersService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return an array of device owners', async () => { | ||
const result = await controller.findAll(); | ||
expect(result).toEqual([]); | ||
expect(service.findAll).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should create a new device owner', async () => { | ||
const createDto: CreateDeviceOwnerDto = { owner_id: 1, user_id: 'test-owner', permission_level: 1, dev_eui: 'test-device-eui' }; | ||
const result = await controller.create(createDto); | ||
expect(result).toEqual({ id: 1, owner_id: 'test-owner' }); | ||
expect(service.create).toHaveBeenCalledWith(createDto); | ||
}); | ||
}); | ||
|
||
describe('FullUpdate', () => { | ||
it('should fully update a device owner', async () => { | ||
const updateDto: UpdateDeviceOwnerDto = { owner_id: 1, user_id: 'test-owner', permission_level: 1, dev_eui: 'test-device-eui' }; | ||
const result = await controller.FullUpdate(1, updateDto); | ||
expect(result).toEqual({ id: 1, owner_id: 'updated-owner' }); | ||
expect(service.fullUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
|
||
describe('PartialUpdate', () => { | ||
it('should partially update a device owner', async () => { | ||
const updateDto: UpdateDeviceOwnerDto = { owner_id: 1, user_id: 'test-owner', permission_level: 1, dev_eui: 'test-device-eui' }; | ||
const result = await controller.PartialUpdate(1, updateDto); | ||
expect(result).toEqual({ id: 1, owner_id: 'partially-updated-owner' }); | ||
expect(service.partialUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,120 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CwDeviceOwnersService } from './cw_device_owners.service'; | ||
import { SupabaseService } from '../supabase/supabase.service'; | ||
import { DevicesOwnersRow } from 'src/common/database-types'; | ||
import { DeviceOwnerRepository } from 'src/repositories/cw_device_owners'; | ||
import { createMockSupabaseClient } from 'src/__mocks__/supabase'; | ||
import { CreateDeviceOwnerDto } from './dto/create-device-owner.dto'; | ||
import { UpdateDeviceOwnerDto } from './dto/update-device-owner.dto'; | ||
|
||
describe('CwDeviceOwnersService', () => { | ||
let service: CwDeviceOwnersService; | ||
let repository: DeviceOwnerRepository; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [CwDeviceOwnersService], | ||
providers: [ | ||
CwDeviceOwnersService, | ||
{ | ||
provide: DeviceOwnerRepository, | ||
useValue: { | ||
findAll: jest.fn().mockResolvedValue([]), | ||
findById: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
owner_id: 'test-owner', | ||
dev_eui: 'test-dev-eui', | ||
}), | ||
create: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
owner_id: 'test-owner', | ||
dev_eui: 'test-dev-eui', | ||
}), | ||
partialUpdate: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
owner_id: 'updated-owner', | ||
}), | ||
fullUpdate: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
owner_id: 'updated-owner', | ||
dev_eui: 'test-dev-eui', | ||
}), | ||
delete: jest.fn().mockResolvedValue(undefined), | ||
findByDevEuiAndUID: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
user_id: 'test-user', | ||
}), | ||
}, | ||
}, | ||
{ | ||
provide: SupabaseService, | ||
useValue: { | ||
getSupabaseClient: createMockSupabaseClient, | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<CwDeviceOwnersService>(CwDeviceOwnersService); | ||
repository = module.get<DeviceOwnerRepository>(DeviceOwnerRepository); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return an array of device owners', async () => { | ||
const result = await service.findAll(); | ||
expect(result).toEqual([]); | ||
expect(repository.findAll).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should create a new device owner', async () => { | ||
const createDto = { owner_id: 1, user_id: 'user_name', permission_level: 1, dev_eui: 'test-dev-eui' } as Partial<DevicesOwnersRow>; | ||
const result = await service.create(createDto as CreateDeviceOwnerDto); | ||
expect(result).toEqual({ id: 1, owner_id: 'test-owner', dev_eui: 'test-dev-eui' }); | ||
expect(repository.create).toHaveBeenCalledWith(createDto); | ||
}); | ||
}); | ||
|
||
describe('partialUpdate', () => { | ||
it('should partially update a device owner', async () => { | ||
const updateDto = { owner_id: 1 } as UpdateDeviceOwnerDto; | ||
const result = await service.partialUpdate(1, updateDto); | ||
expect(result).toEqual({ id: 1, owner_id: 'updated-owner' }); | ||
expect(repository.partialUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
|
||
describe('fullUpdate', () => { | ||
it('should fully update a device owner', async () => { | ||
const updateDto = { owner_id: 1, dev_eui: 'test-dev-eui', user_id: 'user_name', permission_level: 1 } as UpdateDeviceOwnerDto; | ||
const result = await service.fullUpdate(1, updateDto); | ||
expect(result).toEqual({ | ||
id: 1, | ||
owner_id: 'updated-owner', | ||
dev_eui: 'test-dev-eui', | ||
}); | ||
expect(repository.fullUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should delete a device owner', async () => { | ||
const result = await service.delete(1); | ||
expect(result).toBeUndefined(); | ||
expect(repository.delete).toHaveBeenCalledWith(1); | ||
}); | ||
}); | ||
|
||
describe('findByDevEuiAndUID', () => { | ||
it('should return a device owner by dev_eui and user_id', async () => { | ||
const result = await service.getDeviceOwnerByDevEuiAndUID('test-dev-eui', 'test-user'); | ||
expect(result).toEqual({ id: 1, dev_eui: 'test-dev-eui', user_id: 'test-user' }); | ||
expect(repository.findByDevEuiAndUID).toHaveBeenCalledWith('test-dev-eui', 'test-user'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,102 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { CwDevicesController } from './cw_devices.controller'; | ||
import { CwDevicesService } from './cw_devices.service'; | ||
import { CreateDeviceDto } from './dto/create-device.dto'; | ||
|
||
describe('CwDevicesController', () => { | ||
let controller: CwDevicesController; | ||
let service: CwDevicesService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [CwDevicesController], | ||
providers: [ | ||
{ | ||
provide: CwDevicesService, | ||
useValue: { | ||
findAll: jest.fn().mockResolvedValue([]), | ||
findById: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
name: 'Test Device', | ||
}), | ||
create: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
name: 'Test Device', | ||
}), | ||
partialUpdate: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
name: 'Updated Device', | ||
}), | ||
fullUpdate: jest.fn().mockResolvedValue({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
name: 'Updated Device', | ||
}), | ||
delete: jest.fn().mockResolvedValue(undefined), | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
controller = module.get<CwDevicesController>(CwDevicesController); | ||
service = module.get<CwDevicesService>(CwDevicesService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
|
||
describe('findAll', () => { | ||
it('should return an array of devices', async () => { | ||
const result = await controller.findAll(); | ||
expect(result).toEqual([]); | ||
expect(service.findAll).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should create a new device', async () => { | ||
const createDto = { dev_eui: 'test-dev-eui', name: 'Test Device' } as CreateDeviceDto; | ||
const result = await controller.create(createDto); | ||
expect(result).toEqual({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
name: 'Test Device', | ||
}); | ||
expect(service.create).toHaveBeenCalledWith(createDto); | ||
}); | ||
}); | ||
|
||
describe('partialUpdate', () => { | ||
it('should partially update a device', async () => { | ||
const updateDto = { name: 'Updated Device' }; | ||
const result = await controller.PartialUpdate(1, updateDto); | ||
expect(result).toEqual({ id: 1, name: 'Updated Device' }); | ||
expect(service.partialUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
|
||
describe('fullUpdate', () => { | ||
it('should fully update a device', async () => { | ||
const updateDto = { dev_eui: 'test-dev-eui', name: 'Updated Device' }; | ||
const result = await controller.FullUpdate(1, updateDto); | ||
expect(result).toEqual({ | ||
id: 1, | ||
dev_eui: 'test-dev-eui', | ||
name: 'Updated Device', | ||
}); | ||
expect(service.fullUpdate).toHaveBeenCalledWith(1, updateDto); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should delete a device', async () => { | ||
const result = await controller.Delete(1); | ||
expect(result).toBeUndefined(); | ||
// expect(result).toBeUndefined(); | ||
// expect(service.delete).toHaveBeenCalledWith(1); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.