1
- import { verify , action } from '../../../src/writer/follow' ;
2
1
import { FOLLOWS_LIMIT_PER_USER } from '../../../src/helpers/limits' ;
3
2
import db , { sequencerDB } from '../../../src/helpers/mysql' ;
3
+ import { action , verify } from '../../../src/writer/follow' ;
4
4
import { spacesSqlFixtures } from '../../fixtures/space' ;
5
5
6
6
describe ( 'writer/follow' , ( ) => {
@@ -9,7 +9,7 @@ describe('writer/follow', () => {
9
9
10
10
afterAll ( async ( ) => {
11
11
await db . queryAsync ( 'DELETE FROM follows' ) ;
12
- await db . queryAsync ( 'DELETE FROM spaces WHERE id = ?' , [ `${ TEST_PREFIX } - ${ space . id } ` ] ) ;
12
+ await db . queryAsync ( 'DELETE FROM spaces WHERE id LIKE ?' , [ `${ TEST_PREFIX } % ` ] ) ;
13
13
await db . endAsync ( ) ;
14
14
await sequencerDB . endAsync ( ) ;
15
15
} ) ;
@@ -18,14 +18,22 @@ describe('writer/follow', () => {
18
18
const followerId = '0x0' ;
19
19
20
20
beforeAll ( async ( ) => {
21
- let i = 0 ;
21
+ let i = 1 ;
22
22
const promises : Promise < any > [ ] = [ ] ;
23
23
24
24
while ( i <= FOLLOWS_LIMIT_PER_USER ) {
25
+ promises . push (
26
+ db . queryAsync ( 'INSERT INTO snapshot_sequencer_test.spaces SET ?' , {
27
+ ...space ,
28
+ id : `${ TEST_PREFIX } ${ i } .eth` ,
29
+ deleted : 0 ,
30
+ settings : JSON . stringify ( space . settings )
31
+ } )
32
+ ) ;
25
33
promises . push (
26
34
db . queryAsync (
27
35
'INSERT INTO follows SET id = ?, ipfs = ?, follower = ?, space = ?, created = ?' ,
28
- [ i , i , followerId , `test- ${ i } .eth` , i ]
36
+ [ i , i , followerId , `${ TEST_PREFIX } ${ i } .eth` , i ]
29
37
)
30
38
) ;
31
39
@@ -41,6 +49,18 @@ describe('writer/follow', () => {
41
49
) ;
42
50
} ) ;
43
51
52
+ it ( 'ignores deleted spaces from the limit' , async ( ) => {
53
+ await db . queryAsync ( 'UPDATE snapshot_sequencer_test.spaces SET deleted = 1 WHERE id = ?' , [
54
+ `${ TEST_PREFIX } 1.eth`
55
+ ] ) ;
56
+
57
+ await expect ( verify ( { from : followerId } ) ) . resolves . toEqual ( true ) ;
58
+
59
+ return db . queryAsync ( 'UPDATE snapshot_sequencer_test.spaces SET deleted = 0 WHERE id = ?' , [
60
+ `${ TEST_PREFIX } 1.eth`
61
+ ] ) ;
62
+ } ) ;
63
+
44
64
it ( 'returns true when the user has not reached the limit' , ( ) => {
45
65
return expect ( verify ( { from : '0x1' } ) ) . resolves . toEqual ( true ) ;
46
66
} ) ;
@@ -111,15 +131,15 @@ describe('writer/follow', () => {
111
131
it ( 'should increment the follower count of the space' , async ( ) => {
112
132
await db . queryAsync ( 'INSERT INTO spaces SET ?' , {
113
133
...space ,
114
- id : `${ TEST_PREFIX } - ${ space . id } ` ,
134
+ id : `${ TEST_PREFIX } ${ space . id } ` ,
115
135
settings : JSON . stringify ( space . settings )
116
136
} ) ;
117
137
118
138
const id = '3' ;
119
139
const ipfs = '4' ;
120
140
const message = {
121
141
from : '0x4' ,
122
- space : `${ TEST_PREFIX } - ${ space . id } ` ,
142
+ space : `${ TEST_PREFIX } ${ space . id } ` ,
123
143
timestamp : 1
124
144
} ;
125
145
0 commit comments