Skip to content

Commit 97c6a60

Browse files
Remove redundant describe block
1 parent 255acb8 commit 97c6a60

File tree

1 file changed

+149
-151
lines changed

1 file changed

+149
-151
lines changed

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 149 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -55,200 +55,198 @@ describe('lib/optimizely', function() {
5555
createdLogger.log.restore();
5656
});
5757

58-
describe('constructor', function() {
59-
it('should construct an instance of the Optimizely class', function() {
60-
var optlyInstance = new Optimizely({
61-
clientEngine: 'node-sdk',
62-
datafile: testData.getTestProjectConfig(),
63-
errorHandler: stubErrorHandler,
64-
eventDispatcher: stubEventDispatcher,
65-
jsonSchemaValidator: jsonSchemaValidator,
66-
logger: createdLogger,
67-
});
68-
assert.instanceOf(optlyInstance, Optimizely);
69-
sinon.assert.called(createdLogger.log);
70-
var logMessage = createdLogger.log.args[0][1];
71-
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
58+
it('should construct an instance of the Optimizely class', function() {
59+
var optlyInstance = new Optimizely({
60+
clientEngine: 'node-sdk',
61+
datafile: testData.getTestProjectConfig(),
62+
errorHandler: stubErrorHandler,
63+
eventDispatcher: stubEventDispatcher,
64+
jsonSchemaValidator: jsonSchemaValidator,
65+
logger: createdLogger,
7266
});
67+
assert.instanceOf(optlyInstance, Optimizely);
68+
sinon.assert.called(createdLogger.log);
69+
var logMessage = createdLogger.log.args[0][1];
70+
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
71+
});
7372

74-
it('should construct an instance of the Optimizely class when datafile is JSON string', function() {
75-
var optlyInstance = new Optimizely({
76-
clientEngine: 'node-sdk',
77-
datafile: JSON.stringify(testData.getTestProjectConfig()),
78-
errorHandler: stubErrorHandler,
79-
eventDispatcher: stubEventDispatcher,
80-
jsonSchemaValidator: jsonSchemaValidator,
81-
logger: createdLogger,
82-
});
83-
assert.instanceOf(optlyInstance, Optimizely);
84-
sinon.assert.called(createdLogger.log);
85-
var logMessage = createdLogger.log.args[0][1];
86-
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
73+
it('should construct an instance of the Optimizely class when datafile is JSON string', function() {
74+
var optlyInstance = new Optimizely({
75+
clientEngine: 'node-sdk',
76+
datafile: JSON.stringify(testData.getTestProjectConfig()),
77+
errorHandler: stubErrorHandler,
78+
eventDispatcher: stubEventDispatcher,
79+
jsonSchemaValidator: jsonSchemaValidator,
80+
logger: createdLogger,
8781
});
82+
assert.instanceOf(optlyInstance, Optimizely);
83+
sinon.assert.called(createdLogger.log);
84+
var logMessage = createdLogger.log.args[0][1];
85+
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
86+
});
8887

89-
it('should log if the client engine passed in is invalid', function() {
90-
new Optimizely({
91-
datafile: testData.getTestProjectConfig(),
92-
errorHandler: stubErrorHandler,
93-
eventDispatcher: stubEventDispatcher,
94-
logger: createdLogger,
95-
});
88+
it('should log if the client engine passed in is invalid', function() {
89+
new Optimizely({
90+
datafile: testData.getTestProjectConfig(),
91+
errorHandler: stubErrorHandler,
92+
eventDispatcher: stubEventDispatcher,
93+
logger: createdLogger,
94+
});
9695

97-
sinon.assert.called(createdLogger.log);
98-
var logMessage = createdLogger.log.args[0][1];
99-
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, 'OPTIMIZELY', 'undefined'));
96+
sinon.assert.called(createdLogger.log);
97+
var logMessage = createdLogger.log.args[0][1];
98+
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.INVALID_CLIENT_ENGINE, 'OPTIMIZELY', 'undefined'));
99+
});
100+
101+
it('should throw an error if a datafile is not passed into the constructor', function() {
102+
var optly = new Optimizely({
103+
clientEngine: 'node-sdk',
104+
errorHandler: stubErrorHandler,
105+
logger: createdLogger,
100106
});
107+
sinon.assert.calledOnce(stubErrorHandler.handleError);
108+
var errorMessage = stubErrorHandler.handleError.lastCall.args[0].message;
109+
assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.NO_DATAFILE_SPECIFIED, 'OPTIMIZELY'));
101110

102-
it('should throw an error if a datafile is not passed into the constructor', function() {
103-
var optly = new Optimizely({
104-
clientEngine: 'node-sdk',
105-
errorHandler: stubErrorHandler,
106-
logger: createdLogger,
107-
});
108-
sinon.assert.calledOnce(stubErrorHandler.handleError);
109-
var errorMessage = stubErrorHandler.handleError.lastCall.args[0].message;
110-
assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.NO_DATAFILE_SPECIFIED, 'OPTIMIZELY'));
111+
sinon.assert.calledOnce(createdLogger.log);
112+
var logMessage = createdLogger.log.args[0][1];
113+
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.NO_DATAFILE_SPECIFIED, 'OPTIMIZELY'));
111114

112-
sinon.assert.calledOnce(createdLogger.log);
113-
var logMessage = createdLogger.log.args[0][1];
114-
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.NO_DATAFILE_SPECIFIED, 'OPTIMIZELY'));
115+
assert.isFalse(optly.isValidInstance);
116+
});
117+
118+
it('should throw an error if the datafile JSON is malformed', function() {
119+
var invalidDatafileJSON = 'abc';
120+
121+
new Optimizely({
122+
clientEngine: 'node-sdk',
123+
errorHandler: stubErrorHandler,
124+
datafile: invalidDatafileJSON,
125+
jsonSchemaValidator: jsonSchemaValidator,
126+
logger: createdLogger,
127+
});
128+
129+
sinon.assert.calledOnce(createdLogger.log);
130+
var logMessage = createdLogger.log.args[0][1];
131+
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE_MALFORMED, 'OPTIMIZELY'));
132+
});
133+
134+
it('should throw an error if the datafile is not valid', function() {
135+
var invalidDatafile = testData.getTestProjectConfig();
136+
delete invalidDatafile['projectId'];
137+
138+
new Optimizely({
139+
clientEngine: 'node-sdk',
140+
errorHandler: stubErrorHandler,
141+
datafile: invalidDatafile,
142+
jsonSchemaValidator: jsonSchemaValidator,
143+
logger: createdLogger,
144+
});
145+
sinon.assert.calledOnce(stubErrorHandler.handleError);
146+
var errorMessage = stubErrorHandler.handleError.lastCall.args[0].message;
147+
assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE, 'JSON_SCHEMA_VALIDATOR', 'projectId', 'is missing and it is required'));
148+
149+
sinon.assert.calledOnce(createdLogger.log);
150+
var logMessage = createdLogger.log.args[0][1];
151+
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE, 'JSON_SCHEMA_VALIDATOR', 'projectId', 'is missing and it is required'));
152+
});
115153

116-
assert.isFalse(optly.isValidInstance);
154+
describe('skipping JSON schema validation', function() {
155+
beforeEach(function() {
156+
sinon.spy(jsonSchemaValidator, 'validate');
117157
});
118158

119-
it('should throw an error if the datafile JSON is malformed', function() {
120-
var invalidDatafileJSON = 'abc';
159+
afterEach(function() {
160+
jsonSchemaValidator.validate.restore();
161+
});
121162

163+
it('should skip JSON schema validation if skipJSONValidation is passed into instance args with `true` value', function() {
122164
new Optimizely({
123165
clientEngine: 'node-sdk',
166+
datafile: testData.getTestProjectConfig(),
124167
errorHandler: stubErrorHandler,
125-
datafile: invalidDatafileJSON,
126-
jsonSchemaValidator: jsonSchemaValidator,
127-
logger: createdLogger,
168+
eventDispatcher: stubEventDispatcher,
169+
logger: logger.createLogger(),
170+
skipJSONValidation: true,
128171
});
129172

130-
sinon.assert.calledOnce(createdLogger.log);
131-
var logMessage = createdLogger.log.args[0][1];
132-
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE_MALFORMED, 'OPTIMIZELY'));
173+
sinon.assert.notCalled(jsonSchemaValidator.validate);
133174
});
134175

135-
it('should throw an error if the datafile is not valid', function() {
136-
var invalidDatafile = testData.getTestProjectConfig();
137-
delete invalidDatafile['projectId'];
138-
176+
it('should not skip JSON schema validation if skipJSONValidation is passed into instance args with any value other than true', function() {
139177
new Optimizely({
140178
clientEngine: 'node-sdk',
179+
datafile: testData.getTestProjectConfig(),
141180
errorHandler: stubErrorHandler,
142-
datafile: invalidDatafile,
181+
eventDispatcher: stubEventDispatcher,
143182
jsonSchemaValidator: jsonSchemaValidator,
144183
logger: createdLogger,
184+
skipJSONValidation: 'hi',
145185
});
146-
sinon.assert.calledOnce(stubErrorHandler.handleError);
147-
var errorMessage = stubErrorHandler.handleError.lastCall.args[0].message;
148-
assert.strictEqual(errorMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE, 'JSON_SCHEMA_VALIDATOR', 'projectId', 'is missing and it is required'));
149186

187+
sinon.assert.calledOnce(jsonSchemaValidator.validate);
150188
sinon.assert.calledOnce(createdLogger.log);
151189
var logMessage = createdLogger.log.args[0][1];
152-
assert.strictEqual(logMessage, sprintf(ERROR_MESSAGES.INVALID_DATAFILE, 'JSON_SCHEMA_VALIDATOR', 'projectId', 'is missing and it is required'));
190+
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
153191
});
192+
});
154193

155-
describe('skipping JSON schema validation', function() {
156-
beforeEach(function() {
157-
sinon.spy(jsonSchemaValidator, 'validate');
158-
});
194+
describe('when a user profile service is provided', function() {
195+
beforeEach(function() {
196+
sinon.stub(decisionService, 'createDecisionService');
197+
});
159198

160-
afterEach(function() {
161-
jsonSchemaValidator.validate.restore();
162-
});
199+
afterEach(function() {
200+
decisionService.createDecisionService.restore();
201+
});
163202

164-
it('should skip JSON schema validation if skipJSONValidation is passed into instance args with `true` value', function() {
165-
new Optimizely({
166-
clientEngine: 'node-sdk',
167-
datafile: testData.getTestProjectConfig(),
168-
errorHandler: stubErrorHandler,
169-
eventDispatcher: stubEventDispatcher,
170-
logger: logger.createLogger(),
171-
skipJSONValidation: true,
172-
});
203+
it('should validate and pass the user profile service to the decision service', function() {
204+
var userProfileServiceInstance = {
205+
lookup: function() {},
206+
save: function() {},
207+
};
173208

174-
sinon.assert.notCalled(jsonSchemaValidator.validate);
209+
var optlyInstance = new Optimizely({
210+
clientEngine: 'node-sdk',
211+
logger: createdLogger,
212+
datafile: testData.getTestProjectConfig(),
213+
jsonSchemaValidator: jsonSchemaValidator,
214+
userProfileService: userProfileServiceInstance,
175215
});
176216

177-
it('should not skip JSON schema validation if skipJSONValidation is passed into instance args with any value other than true', function() {
178-
new Optimizely({
179-
clientEngine: 'node-sdk',
180-
datafile: testData.getTestProjectConfig(),
181-
errorHandler: stubErrorHandler,
182-
eventDispatcher: stubEventDispatcher,
183-
jsonSchemaValidator: jsonSchemaValidator,
184-
logger: createdLogger,
185-
skipJSONValidation: 'hi',
186-
});
187-
188-
sinon.assert.calledOnce(jsonSchemaValidator.validate);
189-
sinon.assert.calledOnce(createdLogger.log);
190-
var logMessage = createdLogger.log.args[0][1];
191-
assert.strictEqual(logMessage, sprintf(LOG_MESSAGES.VALID_DATAFILE, 'OPTIMIZELY'));
217+
sinon.assert.calledWith(decisionService.createDecisionService, {
218+
configObj: optlyInstance.configObj,
219+
userProfileService: userProfileServiceInstance,
220+
logger: createdLogger,
192221
});
222+
223+
// Checking the second log message as the first one just says "Datafile is valid"
224+
var logMessage = createdLogger.log.args[1][1];
225+
assert.strictEqual(logMessage, 'OPTIMIZELY: Valid user profile service provided.');
193226
});
194227

195-
describe('when a user profile service is provided', function() {
196-
beforeEach(function() {
197-
sinon.stub(decisionService, 'createDecisionService');
198-
});
228+
it('should pass in a null user profile to the decision service if the provided user profile is invalid', function() {
229+
var invalidUserProfile = {
230+
save: function() {},
231+
};
199232

200-
afterEach(function() {
201-
decisionService.createDecisionService.restore();
233+
var optlyInstance = new Optimizely({
234+
clientEngine: 'node-sdk',
235+
logger: createdLogger,
236+
datafile: testData.getTestProjectConfig(),
237+
jsonSchemaValidator: jsonSchemaValidator,
238+
userProfileService: invalidUserProfile,
202239
});
203240

204-
it('should validate and pass the user profile service to the decision service', function() {
205-
var userProfileServiceInstance = {
206-
lookup: function() {},
207-
save: function() {},
208-
};
209-
210-
var optlyInstance = new Optimizely({
211-
clientEngine: 'node-sdk',
212-
logger: createdLogger,
213-
datafile: testData.getTestProjectConfig(),
214-
jsonSchemaValidator: jsonSchemaValidator,
215-
userProfileService: userProfileServiceInstance,
216-
});
217-
218-
sinon.assert.calledWith(decisionService.createDecisionService, {
219-
configObj: optlyInstance.configObj,
220-
userProfileService: userProfileServiceInstance,
221-
logger: createdLogger,
222-
});
223-
224-
// Checking the second log message as the first one just says "Datafile is valid"
225-
var logMessage = createdLogger.log.args[1][1];
226-
assert.strictEqual(logMessage, 'OPTIMIZELY: Valid user profile service provided.');
241+
sinon.assert.calledWith(decisionService.createDecisionService, {
242+
configObj: optlyInstance.configObj,
243+
userProfileService: null,
244+
logger: createdLogger,
227245
});
228246

229-
it('should pass in a null user profile to the decision service if the provided user profile is invalid', function() {
230-
var invalidUserProfile = {
231-
save: function() {},
232-
};
233-
234-
var optlyInstance = new Optimizely({
235-
clientEngine: 'node-sdk',
236-
logger: createdLogger,
237-
datafile: testData.getTestProjectConfig(),
238-
jsonSchemaValidator: jsonSchemaValidator,
239-
userProfileService: invalidUserProfile,
240-
});
241-
242-
sinon.assert.calledWith(decisionService.createDecisionService, {
243-
configObj: optlyInstance.configObj,
244-
userProfileService: null,
245-
logger: createdLogger,
246-
});
247-
248-
// Checking the second log message as the first one just says "Datafile is valid"
249-
var logMessage = createdLogger.log.args[1][1];
250-
assert.strictEqual(logMessage, 'USER_PROFILE_SERVICE_VALIDATOR: Provided user profile service instance is in an invalid format: Missing function \'lookup\'.');
251-
});
247+
// Checking the second log message as the first one just says "Datafile is valid"
248+
var logMessage = createdLogger.log.args[1][1];
249+
assert.strictEqual(logMessage, 'USER_PROFILE_SERVICE_VALIDATOR: Provided user profile service instance is in an invalid format: Missing function \'lookup\'.');
252250
});
253251
});
254252
});

0 commit comments

Comments
 (0)