-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add materialized views unit tests (#1050)
- Loading branch information
1 parent
acaf6d7
commit 38fa3c3
Showing
8 changed files
with
344 additions
and
4 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
58 changes: 58 additions & 0 deletions
58
test/operations/materializedViews/alterMaterializedView.spec.ts
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,58 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterMaterializedView } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('alterMaterializedView', () => { | ||
const alterMaterializedViewFn = alterMaterializedView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterMaterializedViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-04-02: This should throw an error | ||
it('should return sql statement', () => { | ||
const statement = alterMaterializedViewFn('a_mview', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe(`ALTER MATERIALIZED VIEW "a_mview" | ||
;`); | ||
}); | ||
|
||
it('should return sql statement with materializedOptions', () => { | ||
const statement = alterMaterializedViewFn('a_mview', { | ||
cluster: 'a_cluster', | ||
extension: 'a_extension', | ||
storageParameters: { | ||
fillfactor: 70, | ||
fillfactor2: 50, | ||
reset1: null, | ||
reset2: null, | ||
}, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
`ALTER MATERIALIZED VIEW "a_mview" | ||
CLUSTER ON "a_cluster", | ||
DEPENDS ON EXTENSION "a_extension", | ||
SET (fillfactor = 70, fillfactor2 = 50), | ||
RESET (reset1, reset2);` | ||
); | ||
}); | ||
|
||
it('should return sql statement without cluster', () => { | ||
const statement = alterMaterializedViewFn('a_mview', { | ||
cluster: null, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
`ALTER MATERIALIZED VIEW "a_mview" | ||
SET WITHOUT CLUSTER;` | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
test/operations/materializedViews/createMaterializedView.spec.ts
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,77 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createMaterializedView } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('createMaterializedView', () => { | ||
const createMaterializedViewFn = createMaterializedView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createMaterializedViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-04-02: This should throw an error | ||
it.todo('should return sql statement', () => { | ||
const statement = createMaterializedViewFn('order_summary', {}, ''); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('CREATE MATERIALIZED VIEW "order_summary" AS ;'); | ||
}); | ||
|
||
it('should return sql statement with materializedViewOptions', () => { | ||
const statement = createMaterializedViewFn( | ||
'comedies', | ||
{}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'CREATE MATERIALIZED VIEW "comedies" AS SELECT * FROM films WHERE kind = \'Comedy\';' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createMaterializedViewFn( | ||
{ name: 'comedies', schema: 'myschema' }, | ||
{ | ||
ifNotExists: true, | ||
columns: 'kind', | ||
storageParameters: { fillfactor: 70 }, | ||
tablespace: 'mytablespace', | ||
data: true, | ||
// TODO @Shinigami92 2024-04-02: Remove these from the options interface | ||
// ifExists: true, | ||
// cascade: true, | ||
}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'CREATE MATERIALIZED VIEW IF NOT EXISTS "myschema"."comedies"("kind") WITH (fillfactor = 70) TABLESPACE "mytablespace" AS SELECT * FROM films WHERE kind = \'Comedy\' WITH DATA;' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createMaterializedViewFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createMaterializedViewFn.reverse( | ||
{ name: 'comedies', schema: 'myschema' }, | ||
{}, | ||
"SELECT * FROM films WHERE kind = 'Comedy'" | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'DROP MATERIALIZED VIEW "myschema"."comedies";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
test/operations/materializedViews/dropMaterializedView.spec.ts
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,34 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropMaterializedView } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('dropMaterializedView', () => { | ||
const dropMaterializedViewFn = dropMaterializedView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropMaterializedViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropMaterializedViewFn('order_summary'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP MATERIALIZED VIEW "order_summary";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropMaterializedViewFn('order_summary', { | ||
ifExists: true, | ||
cascade: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'DROP MATERIALIZED VIEW IF EXISTS "order_summary" CASCADE;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
test/operations/materializedViews/refreshMaterializedView.spec.ts
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,59 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { refreshMaterializedView } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('refreshMaterializedView', () => { | ||
const refreshMaterializedViewFn = refreshMaterializedView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(refreshMaterializedViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = refreshMaterializedViewFn('order_summary'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('REFRESH MATERIALIZED VIEW "order_summary";'); | ||
}); | ||
|
||
it('should return sql statement with materializedViewRefreshOptions', () => { | ||
const statement = refreshMaterializedViewFn('annual_statistics_basis', { | ||
concurrently: true, | ||
data: false, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'REFRESH MATERIALIZED VIEW CONCURRENTLY "annual_statistics_basis" WITH NO DATA;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = refreshMaterializedViewFn({ | ||
name: 'order_summary', | ||
schema: 'myschema', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'REFRESH MATERIALIZED VIEW "myschema"."order_summary";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(refreshMaterializedViewFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = refreshMaterializedViewFn.reverse('order_summary'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('REFRESH MATERIALIZED VIEW "order_summary";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/operations/materializedViews/renameMaterializedView.spec.ts
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,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameMaterializedView } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('renameMaterializedView', () => { | ||
const renameMaterializedViewFn = renameMaterializedView(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameMaterializedViewFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameMaterializedViewFn('foo', 'bar'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "foo" RENAME TO "bar";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameMaterializedViewFn( | ||
{ name: 'foo', schema: 'myschema' }, | ||
{ name: 'bar', schema: 'myschema' } | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "myschema"."foo" RENAME TO "myschema"."bar";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameMaterializedViewFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameMaterializedViewFn.reverse('foo', 'bar'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "bar" RENAME TO "foo";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
test/operations/materializedViews/renameMaterializedViewColumn.spec.ts
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,61 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameMaterializedViewColumn } from '../../../src/operations/viewsMaterialized'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('materializedViews', () => { | ||
describe('renameMaterializedViewColumn', () => { | ||
const renameMaterializedViewColumnFn = | ||
renameMaterializedViewColumn(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameMaterializedViewColumnFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameMaterializedViewColumnFn( | ||
'a_mview', | ||
'foo', | ||
'bar' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "a_mview" RENAME COLUMN "foo" TO "bar";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameMaterializedViewColumnFn( | ||
{ name: 'a_mview', schema: 'myschema' }, | ||
'foo', | ||
'bar' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "myschema"."a_mview" RENAME COLUMN "foo" TO "bar";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameMaterializedViewColumnFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameMaterializedViewColumnFn.reverse( | ||
'a_mview', | ||
'foo', | ||
'bar' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER MATERIALIZED VIEW "a_mview" RENAME COLUMN "bar" TO "foo";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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