1
1
import { ProjectType } from 'testkit/gql/graphql' ;
2
2
import * as emails from '../../../testkit/emails' ;
3
- import { updateOrgRateLimit , waitFor } from '../../../testkit/flow' ;
3
+ import { pollFor , updateOrgRateLimit , waitFor } from '../../../testkit/flow' ;
4
4
import { initSeed } from '../../../testkit/seed' ;
5
5
6
6
function filterEmailsByOrg ( orgSlug : string , emails : emails . Email [ ] ) {
@@ -15,7 +15,9 @@ function filterEmailsByOrg(orgSlug: string, emails: emails.Email[]) {
15
15
test ( 'rate limit approaching and reached for organization' , async ( ) => {
16
16
const { createOrg, ownerToken, ownerEmail } = await initSeed ( ) . createOwner ( ) ;
17
17
const { createProject, organization } = await createOrg ( ) ;
18
- const { createTargetAccessToken } = await createProject ( ProjectType . Single ) ;
18
+ const { createTargetAccessToken, waitForRequestsCollected } = await createProject (
19
+ ProjectType . Single ,
20
+ ) ;
19
21
20
22
await updateOrgRateLimit (
21
23
{
@@ -44,7 +46,13 @@ test('rate limit approaching and reached for organization', async () => {
44
46
const collectResult = await collectOperations ( new Array ( 10 ) . fill ( op ) ) ;
45
47
expect ( collectResult . status ) . toEqual ( 200 ) ;
46
48
47
- await waitFor ( 8000 ) ;
49
+ await waitForRequestsCollected ( 10 ) ;
50
+
51
+ // wait for the rate limit email to send...
52
+ await pollFor ( async ( ) => {
53
+ let sent = await emails . history ( ) ;
54
+ return filterEmailsByOrg ( organization . slug , sent ) ?. length === 1 ;
55
+ } ) ;
48
56
49
57
let sent = await emails . history ( ) ;
50
58
expect ( sent ) . toContainEqual ( {
@@ -58,7 +66,13 @@ test('rate limit approaching and reached for organization', async () => {
58
66
const collectMoreResult = await collectOperations ( [ op , op ] ) ;
59
67
expect ( collectMoreResult . status ) . toEqual ( 200 ) ;
60
68
61
- await waitFor ( 7000 ) ;
69
+ await waitForRequestsCollected ( 12 ) ;
70
+
71
+ // wait for the quota email to send...
72
+ await pollFor ( async ( ) => {
73
+ let sent = await emails . history ( ) ;
74
+ return filterEmailsByOrg ( organization . slug , sent ) ?. length === 2 ;
75
+ } ) ;
62
76
63
77
sent = await emails . history ( ) ;
64
78
@@ -73,7 +87,8 @@ test('rate limit approaching and reached for organization', async () => {
73
87
const collectEvenMoreResult = await collectOperations ( [ op , op ] ) ;
74
88
expect ( collectEvenMoreResult . status ) . toEqual ( 429 ) ;
75
89
76
- await waitFor ( 5000 ) ;
90
+ // @note we can't poll for any state here because nothing should change. Must wait unfortunately...
91
+ await waitFor ( 4_000 ) ;
77
92
78
93
// Nothing new
79
94
sent = await emails . history ( ) ;
0 commit comments