-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into fix/DTIS-260-sessi…
…on-manage # Conflicts: # src/ui/components/AppWrapper/AppWrapper.tsx
- Loading branch information
Showing
71 changed files
with
3,209 additions
and
396 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { BaseRecord, Tags } from "../../storage/storage.types"; | ||
|
||
interface ConnectionNoteRecordStorageProps { | ||
id?: string; | ||
createdAt?: Date; | ||
tags?: Tags; | ||
connectionId: string; | ||
title: string; | ||
message: string; | ||
} | ||
|
||
class ConnectionNoteRecord extends BaseRecord { | ||
connectionId!: string; | ||
title!: string; | ||
message!: string; | ||
static readonly type = "ConnectionRecord"; | ||
readonly type = ConnectionNoteRecord.type; | ||
|
||
constructor(props: ConnectionNoteRecordStorageProps) { | ||
super(); | ||
if (props) { | ||
this.id = props.id ?? uuidv4(); | ||
this.createdAt = props.createdAt ?? new Date(); | ||
this.connectionId = props.connectionId; | ||
this.title = props.title; | ||
this.message = props.message; | ||
this._tags = props.tags ?? {}; | ||
} | ||
} | ||
|
||
getTags() { | ||
return { | ||
connectionId: this.connectionId, | ||
...this._tags, | ||
}; | ||
} | ||
} | ||
|
||
export type { ConnectionNoteRecordStorageProps }; | ||
export { ConnectionNoteRecord }; |
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 |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import { Query, StorageService } from "../../storage/storage.types"; | ||
import { | ||
ConnectionNoteRecord, | ||
ConnectionNoteRecordStorageProps, | ||
} from "./connectionNoteRecord"; | ||
import { ConnectionNoteStorage } from "./connectionNoteStorage"; | ||
|
||
const storageService = jest.mocked<StorageService<ConnectionNoteRecord>>({ | ||
save: jest.fn(), | ||
delete: jest.fn(), | ||
deleteById: jest.fn(), | ||
update: jest.fn(), | ||
findById: jest.fn(), | ||
findAllByQuery: jest.fn(), | ||
getAll: jest.fn(), | ||
}); | ||
|
||
const connectionNoteStorage = new ConnectionNoteStorage(storageService); | ||
|
||
const id1 = "id1"; | ||
const id2 = "id2"; | ||
|
||
const now = new Date(); | ||
|
||
const connectionNoteRecordProps: ConnectionNoteRecordStorageProps = { | ||
id: id1, | ||
createdAt: now, | ||
connectionId: "connectionId", | ||
title: "title", | ||
message: "message", | ||
tags: {}, | ||
}; | ||
|
||
const connectionNoteRecordA = new ConnectionNoteRecord( | ||
connectionNoteRecordProps | ||
); | ||
|
||
const connectionNoteRecordB = new ConnectionNoteRecord({ | ||
...connectionNoteRecordProps, | ||
id: id2, | ||
}); | ||
|
||
describe("ConnectionNote Storage", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test("Should save connectionNote record", async () => { | ||
storageService.save.mockResolvedValue(connectionNoteRecordA); | ||
await connectionNoteStorage.save(connectionNoteRecordProps); | ||
expect(storageService.save).toBeCalledWith(connectionNoteRecordA); | ||
}); | ||
|
||
test("Should delete connectionNote record", async () => { | ||
storageService.delete.mockResolvedValue(); | ||
await connectionNoteStorage.delete(connectionNoteRecordA); | ||
expect(storageService.delete).toBeCalledWith(connectionNoteRecordA); | ||
}); | ||
|
||
test("Should delete connectionNote record by ID", async () => { | ||
storageService.deleteById.mockResolvedValue(); | ||
await connectionNoteStorage.deleteById(connectionNoteRecordA.id); | ||
expect(storageService.deleteById).toBeCalledWith(connectionNoteRecordA.id); | ||
}); | ||
|
||
test("Should update connectionNote record", async () => { | ||
storageService.update.mockResolvedValue(); | ||
await connectionNoteStorage.update(connectionNoteRecordA); | ||
expect(storageService.update).toBeCalledWith(connectionNoteRecordA); | ||
}); | ||
|
||
test("Should find connectionNote record by ID", async () => { | ||
storageService.findById.mockResolvedValue(connectionNoteRecordA); | ||
const result = await connectionNoteStorage.findById( | ||
connectionNoteRecordA.id | ||
); | ||
expect(result).toEqual(connectionNoteRecordA); | ||
}); | ||
|
||
test("Should find all connectionNote records by query", async () => { | ||
const query: Query<ConnectionNoteRecord> = { | ||
connectionId: "connectionId", | ||
}; | ||
const records = [connectionNoteRecordA, connectionNoteRecordB]; | ||
storageService.findAllByQuery.mockResolvedValue(records); | ||
const result = await connectionNoteStorage.findAllByQuery(query); | ||
expect(result).toEqual(records); | ||
}); | ||
|
||
test("Should get all connectionNote records", async () => { | ||
const records = [connectionNoteRecordA, connectionNoteRecordB]; | ||
storageService.getAll.mockResolvedValue(records); | ||
const result = await connectionNoteStorage.getAll(); | ||
expect(result).toEqual(records); | ||
}); | ||
|
||
// tests error | ||
test("Should handle saving error", async () => { | ||
storageService.save.mockRejectedValue(new Error("Saving error")); | ||
await expect( | ||
connectionNoteStorage.save(connectionNoteRecordProps) | ||
).rejects.toThrow("Saving error"); | ||
}); | ||
|
||
test("Should handle deleting error", async () => { | ||
storageService.delete.mockRejectedValue(new Error("Deleting error")); | ||
await expect( | ||
connectionNoteStorage.delete(connectionNoteRecordA) | ||
).rejects.toThrow("Deleting error"); | ||
}); | ||
|
||
test("Should handle updating error", async () => { | ||
storageService.update.mockRejectedValue(new Error("Updating error")); | ||
await expect( | ||
connectionNoteStorage.update(connectionNoteRecordA) | ||
).rejects.toThrow("Updating error"); | ||
}); | ||
|
||
test("Should handle finding error", async () => { | ||
storageService.findById.mockRejectedValue(new Error("Finding error")); | ||
await expect( | ||
connectionNoteStorage.findById(connectionNoteRecordA.id) | ||
).rejects.toThrow("Finding error"); | ||
}); | ||
|
||
test("Should handle not found", async () => { | ||
storageService.findById.mockResolvedValue(null); | ||
const result = await connectionNoteStorage.findById("nonexistentId"); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
test("Should handle empty result", async () => { | ||
storageService.findAllByQuery.mockResolvedValue([]); | ||
const result = await connectionNoteStorage.findAllByQuery({ filter: {} }); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
test("Should handle empty result for getAll", async () => { | ||
storageService.getAll.mockResolvedValue([]); | ||
const result = await connectionNoteStorage.getAll(); | ||
expect(result).toEqual([]); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Query, StorageService } from "../../storage/storage.types"; | ||
import { | ||
ConnectionNoteRecord, | ||
ConnectionNoteRecordStorageProps, | ||
} from "./connectionNoteRecord"; | ||
|
||
class ConnectionNoteStorage { | ||
private storageService: StorageService<ConnectionNoteRecord>; | ||
|
||
constructor(storageService: StorageService<ConnectionNoteRecord>) { | ||
this.storageService = storageService; | ||
} | ||
|
||
save(props: ConnectionNoteRecordStorageProps): Promise<ConnectionNoteRecord> { | ||
const record = new ConnectionNoteRecord(props); | ||
return this.storageService.save(record); | ||
} | ||
delete(record: ConnectionNoteRecord): Promise<void> { | ||
return this.storageService.delete(record); | ||
} | ||
deleteById(id: string): Promise<void> { | ||
return this.storageService.deleteById(id); | ||
} | ||
update(record: ConnectionNoteRecord): Promise<void> { | ||
return this.storageService.update(record); | ||
} | ||
findById(id: string): Promise<ConnectionNoteRecord | null> { | ||
return this.storageService.findById(id, ConnectionNoteRecord); | ||
} | ||
findAllByQuery( | ||
query: Query<ConnectionNoteRecord> | ||
): Promise<ConnectionNoteRecord[]> { | ||
return this.storageService.findAllByQuery(query, ConnectionNoteRecord); | ||
} | ||
getAll(): Promise<ConnectionNoteRecord[]> { | ||
return this.storageService.getAll(ConnectionNoteRecord); | ||
} | ||
} | ||
|
||
export { ConnectionNoteStorage }; |
Oops, something went wrong.