-
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.
- Loading branch information
1 parent
7d8d9e6
commit 5fc43a6
Showing
4 changed files
with
182 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,33 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { alterRole } from '../../../src/operations/roles'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('roles', () => { | ||
describe('alterRole', () => { | ||
const alterRoleFn = alterRole(options1); | ||
|
||
it('should return a function', () => { | ||
expect(alterRoleFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = alterRoleFn('jonathan', {}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toHaveLength(0); | ||
}); | ||
|
||
it('should return sql statement with roleOptions', () => { | ||
const statement = alterRoleFn('jonathan', { | ||
replication: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER ROLE "jonathan" WITH REPLICATION;' | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,69 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { createRole } from '../../../src/operations/roles'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('roles', () => { | ||
describe('createRole', () => { | ||
const createRoleFn = createRole(options1); | ||
|
||
it('should return a function', () => { | ||
expect(createRoleFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createRoleFn('jonathan'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE ROLE "jonathan" WITH NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN NOREPLICATION;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with roleOptions', () => { | ||
const statement = createRoleFn('miriam', { | ||
login: true, | ||
password: 'jw8s0F4', | ||
valid: '2005-01-01', | ||
superuser: false, | ||
createdb: false, | ||
createrole: false, | ||
inherit: false, | ||
replication: false, | ||
bypassrls: false, | ||
limit: 10, | ||
inRole: 'admin', | ||
role: 'user', | ||
admin: 'admin', | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE ROLE "miriam" WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN NOREPLICATION NOBYPASSRLS CONNECTION LIMIT 10 ENCRYPTED PASSWORD $pga$jw8s0F4$pga$ VALID UNTIL $pga$2005-01-01$pga$ IN ROLE admin ROLE user ADMIN admin;' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = createRoleFn({ name: 'miriam', schema: 'myschema' }); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'CREATE ROLE "myschema"."miriam" WITH NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT NOLOGIN NOREPLICATION;' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(createRoleFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = createRoleFn.reverse('jonathan'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('DROP ROLE "jonathan";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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,31 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { dropRole } from '../../../src/operations/roles'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('roles', () => { | ||
describe('dropRole', () => { | ||
const dropRoleFn = dropRole(options1); | ||
|
||
it('should return a function', () => { | ||
expect(dropRoleFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = dropRoleFn('jonathan'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('DROP ROLE "jonathan";'); | ||
}); | ||
|
||
it('should return sql statement with dropOptions', () => { | ||
const statement = dropRoleFn('jonathan', { | ||
ifExists: true, | ||
}); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual('DROP ROLE IF EXISTS "jonathan";'); | ||
}); | ||
}); | ||
}); | ||
}); |
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,49 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { renameRole } from '../../../src/operations/roles'; | ||
import { options1 } from '../../utils'; | ||
|
||
describe('operations', () => { | ||
describe('roles', () => { | ||
describe('renameRole', () => { | ||
const renameRoleFn = renameRole(options1); | ||
|
||
it('should return a function', () => { | ||
expect(renameRoleFn).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameRoleFn('jonathan', 'davide'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER ROLE "jonathan" RENAME TO "davide";' | ||
); | ||
}); | ||
|
||
it('should return sql statement with schema', () => { | ||
const statement = renameRoleFn( | ||
{ name: 'jonathan', schema: 'myschema' }, | ||
{ name: 'davide', schema: 'myschema' } | ||
); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toStrictEqual( | ||
'ALTER ROLE "myschema"."jonathan" RENAME TO "myschema"."davide";' | ||
); | ||
}); | ||
|
||
describe('reverse', () => { | ||
it('should contain a reverse function', () => { | ||
expect(renameRoleFn.reverse).toBeTypeOf('function'); | ||
}); | ||
|
||
it('should return sql statement', () => { | ||
const statement = renameRoleFn.reverse('jonathan', 'davide'); | ||
|
||
expect(statement).toBeTypeOf('string'); | ||
expect(statement).toBe('ALTER ROLE "davide" RENAME TO "jonathan";'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |