Skip to content

Commit b38a3d0

Browse files
committed
fix test leak
1 parent d7f8c9d commit b38a3d0

File tree

2 files changed

+179
-170
lines changed

2 files changed

+179
-170
lines changed

test/attributeFields.test.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,38 @@ import {
1818
} from 'graphql';
1919

2020
describe('attributeFields', function () {
21-
var Model = sequelize.define(Math.random().toString(), {
22-
email: {
23-
type: Sequelize.STRING,
24-
allowNull: false
25-
},
26-
firstName: {
27-
type: Sequelize.STRING
28-
},
29-
lastName: {
30-
type: Sequelize.STRING
31-
},
32-
float: {
33-
type: Sequelize.FLOAT
34-
},
35-
enum: {
36-
type: Sequelize.ENUM('first', 'second')
37-
},
38-
list: {
39-
type: Sequelize.ARRAY(Sequelize.STRING)
40-
},
41-
virtualInteger: {
42-
type: new Sequelize.VIRTUAL(Sequelize.INTEGER)
43-
},
44-
virtualBoolean: {
45-
type: new Sequelize.VIRTUAL(Sequelize.BOOLEAN)
46-
}
47-
}, {
48-
timestamps: false
21+
var Model;
22+
23+
before(function () {
24+
Model = sequelize.define(Math.random().toString(), {
25+
email: {
26+
type: Sequelize.STRING,
27+
allowNull: false
28+
},
29+
firstName: {
30+
type: Sequelize.STRING
31+
},
32+
lastName: {
33+
type: Sequelize.STRING
34+
},
35+
float: {
36+
type: Sequelize.FLOAT
37+
},
38+
enum: {
39+
type: Sequelize.ENUM('first', 'second')
40+
},
41+
list: {
42+
type: Sequelize.ARRAY(Sequelize.STRING)
43+
},
44+
virtualInteger: {
45+
type: new Sequelize.VIRTUAL(Sequelize.INTEGER)
46+
},
47+
virtualBoolean: {
48+
type: new Sequelize.VIRTUAL(Sequelize.BOOLEAN)
49+
}
50+
}, {
51+
timestamps: false
52+
});
4953
});
5054

5155
it('should return fields for a simple model', function () {

test/resolver.test.js

Lines changed: 147 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -30,175 +30,180 @@ describe('resolver', function () {
3030
, labelType
3131
, schema;
3232

33-
User = sequelize.define('user', {
34-
name: Sequelize.STRING,
35-
myVirtual: {
36-
type: Sequelize.VIRTUAL,
37-
get: function() {
38-
return 'lol';
33+
before(function () {
34+
sequelize.modelManager.models = [];
35+
sequelize.models = {};
36+
37+
User = sequelize.define('user', {
38+
name: Sequelize.STRING,
39+
myVirtual: {
40+
type: Sequelize.VIRTUAL,
41+
get: function() {
42+
return 'lol';
43+
}
3944
}
40-
}
41-
}, {
42-
timestamps: false
43-
});
45+
}, {
46+
timestamps: false
47+
});
4448

45-
Task = sequelize.define('task', {
46-
title: Sequelize.STRING,
47-
createdAt: {
48-
type: Sequelize.DATE,
49-
field: 'created_at',
50-
defaultValue: Sequelize.NOW
51-
},
52-
taskVirtual: {
53-
type: Sequelize.VIRTUAL,
54-
get: function() {
55-
return 'tasktask';
49+
Task = sequelize.define('task', {
50+
title: Sequelize.STRING,
51+
createdAt: {
52+
type: Sequelize.DATE,
53+
field: 'created_at',
54+
defaultValue: Sequelize.NOW
55+
},
56+
taskVirtual: {
57+
type: Sequelize.VIRTUAL,
58+
get: function() {
59+
return 'tasktask';
60+
}
5661
}
57-
}
58-
}, {
59-
timestamps: false
60-
});
62+
}, {
63+
timestamps: false
64+
});
6165

62-
Project = sequelize.define('project', {
63-
name: Sequelize.STRING
64-
}, {
65-
timestamps: false
66-
});
66+
Project = sequelize.define('project', {
67+
name: Sequelize.STRING
68+
}, {
69+
timestamps: false
70+
});
6771

68-
Label = sequelize.define('label', {
69-
name: Sequelize.STRING
70-
}, {
71-
timestamps: false
72-
});
72+
Label = sequelize.define('label', {
73+
name: Sequelize.STRING
74+
}, {
75+
timestamps: false
76+
});
7377

74-
User.Tasks = User.hasMany(Task, {as: 'tasks', foreignKey: 'userId'});
75-
Task.User = Task.belongsTo(User, {as: 'user', foreignKey: 'userId'});
78+
User.Tasks = User.hasMany(Task, {as: 'tasks', foreignKey: 'userId'});
79+
Task.User = Task.belongsTo(User, {as: 'user', foreignKey: 'userId'});
7680

77-
Task.Project = Task.belongsTo(Project, {as: 'project', foreignKey: 'projectId'});
78-
Project.Labels = Project.hasMany(Label, {as: 'labels'});
81+
Task.Project = Task.belongsTo(Project, {as: 'project', foreignKey: 'projectId'});
82+
Project.Labels = Project.hasMany(Label, {as: 'labels'});
7983

80-
labelType = new GraphQLObjectType({
81-
name: 'Label',
82-
fields: {
83-
id: {
84-
type: new GraphQLNonNull(GraphQLInt)
85-
},
86-
name: {
87-
type: GraphQLString
88-
}
89-
}
90-
});
91-
92-
projectType = new GraphQLObjectType({
93-
name: 'Project',
94-
fields: {
95-
id: {
96-
type: new GraphQLNonNull(GraphQLInt)
97-
},
98-
name: {
99-
type: GraphQLString
100-
},
101-
labels: {
102-
type: new GraphQLList(labelType),
103-
resolve: resolver(Project.Labels)
84+
labelType = new GraphQLObjectType({
85+
name: 'Label',
86+
fields: {
87+
id: {
88+
type: new GraphQLNonNull(GraphQLInt)
89+
},
90+
name: {
91+
type: GraphQLString
92+
}
10493
}
105-
}
106-
});
94+
});
10795

108-
taskType = new GraphQLObjectType({
109-
name: 'Task',
110-
description: 'A task',
111-
fields: {
112-
id: {
113-
type: new GraphQLNonNull(GraphQLInt)
114-
},
115-
title: {
116-
type: GraphQLString
117-
},
118-
taskVirtual: {
119-
type: GraphQLString
120-
},
121-
project: {
122-
type: projectType,
123-
resolve: resolver(Task.Project)
96+
projectType = new GraphQLObjectType({
97+
name: 'Project',
98+
fields: {
99+
id: {
100+
type: new GraphQLNonNull(GraphQLInt)
101+
},
102+
name: {
103+
type: GraphQLString
104+
},
105+
labels: {
106+
type: new GraphQLList(labelType),
107+
resolve: resolver(Project.Labels)
108+
}
124109
}
125-
}
126-
});
110+
});
127111

128-
userType = new GraphQLObjectType({
129-
name: 'User',
130-
description: 'A user',
131-
fields: {
132-
id: {
133-
type: new GraphQLNonNull(GraphQLInt),
134-
},
135-
name: {
136-
type: GraphQLString,
137-
},
138-
myVirtual: {
139-
type: GraphQLString
140-
},
141-
tasks: {
142-
type: new GraphQLList(taskType),
143-
args: {
144-
limit: {
145-
type: GraphQLInt
146-
},
147-
offset: {
148-
type: GraphQLInt
149-
},
150-
order: {
151-
type: GraphQLString
152-
},
153-
first: {
154-
type: GraphQLInt
155-
}
112+
taskType = new GraphQLObjectType({
113+
name: 'Task',
114+
description: 'A task',
115+
fields: {
116+
id: {
117+
type: new GraphQLNonNull(GraphQLInt)
156118
},
157-
resolve: resolver(User.Tasks, {
158-
before: function(options, args) {
159-
if (args.first) {
160-
options.order = options.order || [];
161-
options.order.push(['created_at', 'ASC']);
162-
163-
if (args.first !== 0) {
164-
options.limit = args.first;
165-
}
166-
}
167-
168-
return options;
169-
}
170-
})
119+
title: {
120+
type: GraphQLString
121+
},
122+
taskVirtual: {
123+
type: GraphQLString
124+
},
125+
project: {
126+
type: projectType,
127+
resolve: resolver(Task.Project)
128+
}
171129
}
172-
}
173-
});
130+
});
174131

175-
schema = new GraphQLSchema({
176-
query: new GraphQLObjectType({
177-
name: 'RootQueryType',
132+
userType = new GraphQLObjectType({
133+
name: 'User',
134+
description: 'A user',
178135
fields: {
179-
user: {
180-
type: userType,
181-
args: {
182-
id: {
183-
type: new GraphQLNonNull(GraphQLInt)
184-
}
185-
},
186-
resolve: resolver(User)
136+
id: {
137+
type: new GraphQLNonNull(GraphQLInt),
187138
},
188-
users: {
189-
type: new GraphQLList(userType),
139+
name: {
140+
type: GraphQLString,
141+
},
142+
myVirtual: {
143+
type: GraphQLString
144+
},
145+
tasks: {
146+
type: new GraphQLList(taskType),
190147
args: {
191148
limit: {
192149
type: GraphQLInt
193150
},
151+
offset: {
152+
type: GraphQLInt
153+
},
194154
order: {
195155
type: GraphQLString
156+
},
157+
first: {
158+
type: GraphQLInt
196159
}
197160
},
198-
resolve: resolver(User)
161+
resolve: resolver(User.Tasks, {
162+
before: function(options, args) {
163+
if (args.first) {
164+
options.order = options.order || [];
165+
options.order.push(['created_at', 'ASC']);
166+
167+
if (args.first !== 0) {
168+
options.limit = args.first;
169+
}
170+
}
171+
172+
return options;
173+
}
174+
})
199175
}
200176
}
201-
})
177+
});
178+
179+
schema = new GraphQLSchema({
180+
query: new GraphQLObjectType({
181+
name: 'RootQueryType',
182+
fields: {
183+
user: {
184+
type: userType,
185+
args: {
186+
id: {
187+
type: new GraphQLNonNull(GraphQLInt)
188+
}
189+
},
190+
resolve: resolver(User)
191+
},
192+
users: {
193+
type: new GraphQLList(userType),
194+
args: {
195+
limit: {
196+
type: GraphQLInt
197+
},
198+
order: {
199+
type: GraphQLString
200+
}
201+
},
202+
resolve: resolver(User)
203+
}
204+
}
205+
})
206+
});
202207
});
203208

204209
before(function () {

0 commit comments

Comments
 (0)