1
- import { createTestNode } from "@test-utils" ;
1
+ /** @jest -environment ./src/__test__/utils/enableVersionCheck.ts */
2
+
3
+ import { createTestNode , matchServerVersion } from "@test-utils" ;
2
4
3
5
import {
4
6
ABORTED ,
@@ -8,7 +10,7 @@ import {
8
10
UnknownError ,
9
11
} from "@eventstore/db-client" ;
10
12
11
- describe ( "disableProjection " , ( ) => {
13
+ describe ( "disable / abort " , ( ) => {
12
14
const node = createTestNode ( ) ;
13
15
let client ! : EventStoreDBClient ;
14
16
@@ -36,11 +38,11 @@ describe("disableProjection", () => {
36
38
await node . down ( ) ;
37
39
} ) ;
38
40
39
- describe ( "disables the projection " , ( ) => {
40
- test ( "write a checkpoint " , async ( ) => {
41
- const PROJECTION_NAME = "projection_to_disable_with_checkpoint " ;
41
+ describe ( "disableProjection " , ( ) => {
42
+ test ( "disables the projection " , async ( ) => {
43
+ const PROJECTION_NAME = "projection_to_disable " ;
42
44
43
- await client . createContinuousProjection ( PROJECTION_NAME , projection ) ;
45
+ await client . createProjection ( PROJECTION_NAME , projection ) ;
44
46
45
47
const beforeDetails = await client . getProjectionStatistics (
46
48
PROJECTION_NAME
@@ -49,25 +51,39 @@ describe("disableProjection", () => {
49
51
expect ( beforeDetails ) . toBeDefined ( ) ;
50
52
expect ( beforeDetails . projectionStatus ) . toBe ( RUNNING ) ;
51
53
52
- await client . disableProjection ( PROJECTION_NAME , {
53
- writeCheckpoint : true ,
54
- } ) ;
54
+ await client . disableProjection ( PROJECTION_NAME ) ;
55
55
56
56
const afterDetails = await client . getProjectionStatistics (
57
57
PROJECTION_NAME
58
58
) ;
59
59
60
60
expect ( afterDetails ) . toBeDefined ( ) ;
61
61
62
- // Incorrect projection status was switched (ABORTED -> STOPPED) in
63
- // https://github.com/EventStore/EventStore/pull/2944
64
- expect ( [ STOPPED , ABORTED ] ) . toContain ( afterDetails . projectionStatus ) ;
62
+ if ( matchServerVersion `>=21.10` ) {
63
+ expect ( afterDetails . projectionStatus ) . toBe ( STOPPED ) ;
64
+ } else {
65
+ // Incorrect projection status was switched (ABORTED -> STOPPED) in
66
+ // https://github.com/EventStore/EventStore/pull/2944
67
+ expect ( [ STOPPED , ABORTED ] ) . toContain ( afterDetails . projectionStatus ) ;
68
+ }
69
+ } ) ;
70
+ } ) ;
71
+
72
+ describe ( "errors" , ( ) => {
73
+ test ( "projection doesnt exist" , async ( ) => {
74
+ const PROJECTION_NAME = "doesnt exist" ;
75
+
76
+ await expect (
77
+ client . disableProjection ( PROJECTION_NAME )
78
+ ) . rejects . toThrowError ( UnknownError ) ; // https://github.com/EventStore/EventStore/issues/2732
65
79
} ) ;
80
+ } ) ;
66
81
67
- test ( "do not write a checkpoint" , async ( ) => {
68
- const PROJECTION_NAME = "projection_to_disable_without_checkpoint" ;
82
+ describe ( "abortProjection" , ( ) => {
83
+ test ( "aborts the projection" , async ( ) => {
84
+ const PROJECTION_NAME = "projection_to_abort" ;
69
85
70
- await client . createContinuousProjection ( PROJECTION_NAME , projection ) ;
86
+ await client . createProjection ( PROJECTION_NAME , projection ) ;
71
87
72
88
const beforeDetails = await client . getProjectionStatistics (
73
89
PROJECTION_NAME
@@ -76,29 +92,31 @@ describe("disableProjection", () => {
76
92
expect ( beforeDetails ) . toBeDefined ( ) ;
77
93
expect ( beforeDetails . projectionStatus ) . toBe ( RUNNING ) ;
78
94
79
- await client . disableProjection ( PROJECTION_NAME , {
80
- writeCheckpoint : false ,
81
- } ) ;
95
+ await client . abortProjection ( PROJECTION_NAME ) ;
82
96
83
97
const afterDetails = await client . getProjectionStatistics (
84
98
PROJECTION_NAME
85
99
) ;
86
100
87
101
expect ( afterDetails ) . toBeDefined ( ) ;
88
102
89
- // Incorrect projection status was fixed (STOPPED -> ABORTED) in
90
- // https://github.com/EventStore/EventStore/pull/2944
91
- expect ( [ ABORTED , STOPPED ] ) . toContain ( afterDetails . projectionStatus ) ;
103
+ if ( matchServerVersion `>=21.10` ) {
104
+ expect ( afterDetails . projectionStatus ) . toBe ( ABORTED ) ;
105
+ } else {
106
+ // Incorrect projection status was switched (ABORTED -> STOPPED) in
107
+ // https://github.com/EventStore/EventStore/pull/2944
108
+ expect ( [ STOPPED , ABORTED ] ) . toContain ( afterDetails . projectionStatus ) ;
109
+ }
92
110
} ) ;
93
- } ) ;
94
111
95
- describe ( "errors" , ( ) => {
96
- test ( "projection doesnt exist" , async ( ) => {
97
- const PROJECTION_NAME = "doesnt exist" ;
112
+ describe ( "errors" , ( ) => {
113
+ test ( "projection doesnt exist" , async ( ) => {
114
+ const PROJECTION_NAME = "doesnt exist" ;
98
115
99
- await expect (
100
- client . disableProjection ( PROJECTION_NAME )
101
- ) . rejects . toThrowError ( UnknownError ) ; // https://github.com/EventStore/EventStore/issues/2732
116
+ await expect (
117
+ client . abortProjection ( PROJECTION_NAME )
118
+ ) . rejects . toThrowError ( UnknownError ) ; // https://github.com/EventStore/EventStore/issues/2732
119
+ } ) ;
102
120
} ) ;
103
121
} ) ;
104
122
} ) ;
0 commit comments