mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
Added two new tests, modified two existing tests
`should return if minimum supported PostgreSQL and vectors version are installed`:
Check if init returns properly and that getPostgresVersion is called twice
`should thrown an error if PostgreSQL version is below minimum supported version`:
Checks if the init function correctly returns an error
`should suggest image with postgres ${major} if database is ${major}`:
Modified to set MockResolvedValue instead of MockResolvedValueOnce. With the new check we get the PostgreSQL version twice. So it needs to be set during the entire test.
`should not suggest image if postgres version is not in 14, 15 or 16`:
Modified the bounds to [14, 18]. Because values below 14 now will not get called.
Also Modified to call `getPostgresVersion.MockResolvedValueOnce` for twice, because it gets called twice.
This commit is contained in:
parent
1cd2f2482e
commit
2abcb600fe
1 changed files with 27 additions and 2 deletions
|
|
@ -28,6 +28,28 @@ describe(DatabaseService.name, () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('init', () => {
|
describe('init', () => {
|
||||||
|
it('should return if minimum supported PostgreSQL and vectors version are installed', async () => {
|
||||||
|
databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(14, 0, 0));
|
||||||
|
databaseMock.getExtensionVersion.mockResolvedValueOnce(new Version(0, 1, 1));
|
||||||
|
|
||||||
|
await sut.init();
|
||||||
|
|
||||||
|
expect(databaseMock.getPostgresVersion).toHaveBeenCalledTimes(2);
|
||||||
|
expect(databaseMock.createExtension).toHaveBeenCalledWith(DatabaseExtension.VECTORS);
|
||||||
|
expect(databaseMock.createExtension).toHaveBeenCalledTimes(1);
|
||||||
|
expect(databaseMock.getExtensionVersion).toHaveBeenCalledTimes(1);
|
||||||
|
expect(databaseMock.runMigrations).toHaveBeenCalledTimes(1);
|
||||||
|
expect(fatalLog).not.toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should thrown an error if PostgreSQL version is below minimum supported version', async () => {
|
||||||
|
databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(13, 0, 0));
|
||||||
|
|
||||||
|
await expect(sut.init()).rejects.toThrow(/^(?:(?!PostgreSQL).)*$/s);
|
||||||
|
|
||||||
|
expect(databaseMock.getPostgresVersion).toHaveBeenCalledTimes(1);
|
||||||
|
})
|
||||||
|
|
||||||
it('should return if minimum supported vectors version is installed', async () => {
|
it('should return if minimum supported vectors version is installed', async () => {
|
||||||
databaseMock.getExtensionVersion.mockResolvedValueOnce(new Version(0, 1, 1));
|
databaseMock.getExtensionVersion.mockResolvedValueOnce(new Version(0, 1, 1));
|
||||||
|
|
||||||
|
|
@ -108,7 +130,7 @@ describe(DatabaseService.name, () => {
|
||||||
for (const major of [14, 15, 16]) {
|
for (const major of [14, 15, 16]) {
|
||||||
it(`should suggest image with postgres ${major} if database is ${major}`, async () => {
|
it(`should suggest image with postgres ${major} if database is ${major}`, async () => {
|
||||||
databaseMock.getExtensionVersion.mockResolvedValue(new Version(0, 0, 1));
|
databaseMock.getExtensionVersion.mockResolvedValue(new Version(0, 0, 1));
|
||||||
databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0));
|
databaseMock.getPostgresVersion.mockResolvedValue(new Version(major, 0, 0));
|
||||||
|
|
||||||
await expect(sut.init()).rejects.toThrow(new RegExp(`tensorchord\/pgvecto-rs:pg${major}-v0\\.1\\.11`, 's'));
|
await expect(sut.init()).rejects.toThrow(new RegExp(`tensorchord\/pgvecto-rs:pg${major}-v0\\.1\\.11`, 's'));
|
||||||
});
|
});
|
||||||
|
|
@ -116,7 +138,10 @@ describe(DatabaseService.name, () => {
|
||||||
|
|
||||||
it('should not suggest image if postgres version is not in 14, 15 or 16', async () => {
|
it('should not suggest image if postgres version is not in 14, 15 or 16', async () => {
|
||||||
databaseMock.getExtensionVersion.mockResolvedValue(new Version(0, 0, 1));
|
databaseMock.getExtensionVersion.mockResolvedValue(new Version(0, 0, 1));
|
||||||
[13, 17].forEach((major) => databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0)));
|
[14, 18].forEach((major) => {
|
||||||
|
databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0));
|
||||||
|
databaseMock.getPostgresVersion.mockResolvedValueOnce(new Version(major, 0, 0))
|
||||||
|
});
|
||||||
|
|
||||||
await expect(sut.init()).rejects.toThrow(/^(?:(?!tensorchord\/pgvecto-rs).)*$/s);
|
await expect(sut.init()).rejects.toThrow(/^(?:(?!tensorchord\/pgvecto-rs).)*$/s);
|
||||||
await expect(sut.init()).rejects.toThrow(/^(?:(?!tensorchord\/pgvecto-rs).)*$/s);
|
await expect(sut.init()).rejects.toThrow(/^(?:(?!tensorchord\/pgvecto-rs).)*$/s);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue