-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add policies unit tests (#1026)
- Loading branch information
1 parent
f111be5
commit f032440
Showing
4 changed files
with
185 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterPolicy } from '../../../src/operations/policies'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('policies', () => { | ||
describe('alterPolicy', () => { | ||
const alterPolicyFn = alterPolicy(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterPolicyFn).toBeTypeOf('function'); | ||
}); | ||
|
||
// TODO @Shinigami92 2024-03-09: This should throw an error | ||
it('should return sql statement', () => { | ||
const statement = alterPolicyFn('my_table', 'p1', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('ALTER POLICY "p1" ON "my_table" ;'); | ||
}); | ||
|
||
it('should return sql statement with policyOptions', () => { | ||
const statement = alterPolicyFn('my_table', 'p1', { | ||
role: 'CURRENT_USER', | ||
check: 'true', | ||
using: 'true', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER POLICY "p1" ON "my_table" TO CURRENT_USER USING (true) WITH CHECK (true);' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,64 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createPolicy } from '../../../src/operations/policies'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('policies', () => { | ||
describe('createPolicy', () => { | ||
const createPolicyFn = createPolicy(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createPolicyFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createPolicyFn('my_table', 'p1'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE POLICY "p1" ON "my_table" FOR ALL TO PUBLIC;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with policyOptions', () => { | ||
const statement = createPolicyFn('my_table', 'p1', { | ||
role: 'CURRENT_USER', | ||
check: 'true', | ||
using: 'true', | ||
command: 'SELECT', | ||
ifExists: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE POLICY "p1" ON "my_table" FOR SELECT TO CURRENT_USER USING (true) WITH CHECK (true);' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createPolicyFn( | ||
{ name: 'my_table', schema: 'myschema' }, | ||
'p1' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE POLICY "p1" ON "myschema"."my_table" FOR ALL TO PUBLIC;' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createPolicyFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createPolicyFn.reverse('my_table', 'p1'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP POLICY "p1" ON "my_table";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropPolicy } from '../../../src/operations/policies'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('policies', () => { | ||
describe('dropPolicy', () => { | ||
const dropPolicyFn = dropPolicy(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropPolicyFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropPolicyFn('my_table', 'p1'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('DROP POLICY "p1" ON "my_table";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropPolicyFn('my_table', 'p1', { | ||
ifExists: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'DROP POLICY IF EXISTS "p1" ON "my_table";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,52 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renamePolicy } from '../../../src/operations/policies'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('policies', () => { | ||
describe('renamePolicy', () => { | ||
const renamePolicyFn = renamePolicy(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renamePolicyFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renamePolicyFn('my_table', 'p1', 'p2'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER POLICY "p1" ON "my_table" RENAME TO "p2";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renamePolicyFn( | ||
{ name: 'my_table', schema: 'myschema' }, | ||
'p1', | ||
'p2' | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER POLICY "p1" ON "myschema"."my_table" RENAME TO "p2";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renamePolicyFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renamePolicyFn.reverse('my_table', 'p1', 'p2'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe( | ||
'ALTER POLICY "p2" ON "my_table" RENAME TO "p1";' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |