11const sinon = require ( 'sinon' ) ;
22const domainEvents = require ( '@tryghost/domain-events' ) ;
3+ const assert = require ( 'node:assert/strict' ) ;
34const models = require ( '../../../core/server/models' ) ;
45const { getSignedAdminToken} = require ( '../../../core/server/adapters/scheduling/utils' ) ;
5- const { agentProvider, fixtureManager, matchers, assertions} = require ( '../../utils/e2e-framework' ) ;
6+ const { agentProvider, dbUtils , fixtureManager, matchers, assertions} = require ( '../../utils/e2e-framework' ) ;
67const StartAutomationsPollEvent = require ( '../../../core/server/services/welcome-email-automations/events/start-automations-poll-event' ) ;
78
89const { anyContentVersion, anyEtag, anyErrorId} = matchers ;
@@ -15,7 +16,8 @@ describe('Automations API', function () {
1516
1617 before ( async function ( ) {
1718 agent = await agentProvider . getAdminAPIAgent ( ) ;
18- await fixtureManager . init ( 'integrations' , 'api_keys' ) ;
19+ await fixtureManager . init ( 'users' , 'integrations' , 'api_keys' ) ;
20+ await agent . loginAsOwner ( ) ;
1921
2022 schedulerIntegration = await models . Integration . findOne (
2123 { slug : 'ghost-scheduler' } ,
@@ -33,6 +35,42 @@ describe('Automations API', function () {
3335 sinon . restore ( ) ;
3436 } ) ;
3537
38+ describe ( 'browse' , function ( ) {
39+ beforeEach ( async function ( ) {
40+ await dbUtils . truncate ( 'welcome_email_automated_emails' ) ;
41+ await dbUtils . truncate ( 'welcome_email_automations' ) ;
42+ } ) ;
43+
44+ it ( 'returns welcome email automations ordered by creation time' , async function ( ) {
45+ const second = await models . WelcomeEmailAutomation . add ( {
46+ name : 'Welcome Email (Premium)' ,
47+ slug : 'member-welcome-email-premium' ,
48+ status : 'inactive' ,
49+ created_at : new Date ( '2025-01-02T00:00:00Z' )
50+ } ) ;
51+ const first = await models . WelcomeEmailAutomation . add ( {
52+ name : 'Welcome Email (Free)' ,
53+ slug : 'member-welcome-email-free' ,
54+ status : 'active' ,
55+ created_at : new Date ( '2025-01-01T00:00:00Z' )
56+ } ) ;
57+
58+ const { body} = await agent
59+ . get ( 'automations' )
60+ . expectStatus ( 200 ) ;
61+
62+ assert . deepEqual ( body . automations , [ {
63+ id : first . id ,
64+ name : first . get ( 'name' ) ,
65+ status : first . get ( 'status' )
66+ } , {
67+ id : second . id ,
68+ name : second . get ( 'name' ) ,
69+ status : second . get ( 'status' )
70+ } ] ) ;
71+ } ) ;
72+ } ) ;
73+
3674 describe ( 'poll' , function ( ) {
3775 /** @type {sinon.SinonStub } */
3876 let dispatchStub ;
0 commit comments