@@ -2,39 +2,47 @@ import { Db, Trigger } from "../src/index";
22import getDb from "./test-helper/get-db" ;
33
44let db : Db ;
5- let trigger : Trigger ;
5+ let accountTrigger : Trigger ;
66
77beforeAll ( async ( ) => {
88 db = await getDb ( ) ;
9- trigger = db . schemas . get ( "public" ) . tables . get ( "account" ) . triggers . get ( "account_trigger" ) ;
9+ accountTrigger = db . schemas . get ( "public" ) . tables . get ( "account" ) . triggers . get ( "account_trigger" ) ;
1010} ) ;
1111
1212describe ( "Trigger" , ( ) => {
13+ it ( "should exist." , ( ) => {
14+ // Test that we can find a trigger with and without the WHEN clause.
15+ const withWhen = db . schemas . get ( "public" ) . tables . get ( "account" ) . triggers . get ( "account_trigger" , { throwUnknown : false } ) ;
16+ expect ( withWhen ) . not . toBeUndefined ( ) ;
17+ const withoutWhen = db . schemas . get ( "public" ) . tables . get ( "account" ) . triggers . get ( "account_updated_at" , { throwUnknown : false } ) ;
18+ expect ( withoutWhen ) . not . toBeUndefined ( ) ;
19+ } ) ;
20+
1321 it ( "should have name." , ( ) => {
14- expect ( trigger . name ) . toBe ( "account_trigger" ) ;
22+ expect ( accountTrigger . name ) . toBe ( "account_trigger" ) ;
1523 } ) ;
1624
1725 it ( "should have table." , ( ) => {
18- expect ( trigger ?. table ?. name ) . toBe ( "account" ) ;
26+ expect ( accountTrigger ?. table ?. name ) . toBe ( "account" ) ;
1927 } ) ;
2028
2129 it ( "should have view." , ( ) => {
22- expect ( trigger ?. view ?. name ) . toBeUndefined ( ) ;
30+ expect ( accountTrigger ?. view ?. name ) . toBeUndefined ( ) ;
2331 } ) ;
2432
2533 it ( "should have schema." , ( ) => {
26- expect ( trigger . schema . name ) . toBe ( "public" ) ;
34+ expect ( accountTrigger . schema . name ) . toBe ( "public" ) ;
2735 } ) ;
2836
2937 it ( "should have full name." , ( ) => {
30- expect ( trigger . fullName ) . toBe ( "public.account.account_trigger" ) ;
38+ expect ( accountTrigger . fullName ) . toBe ( "public.account.account_trigger" ) ;
3139 } ) ;
3240
3341 it ( "should have events." , ( ) => {
34- expect ( trigger . events ) . toEqual ( [ "insert" , "delete" , "update" ] ) ;
42+ expect ( accountTrigger . events ) . toEqual ( [ "insert" , "delete" , "update" ] ) ;
3543 } ) ;
3644
3745 it ( "should have function." , ( ) => {
38- expect ( trigger . function . name ) . toBe ( "trigger_returning_function" ) ;
46+ expect ( accountTrigger . function . name ) . toBe ( "trigger_returning_function" ) ;
3947 } ) ;
4048} ) ;
0 commit comments