Skip to content

Commit 3f52014

Browse files
committed
Unit tests for redaction and generate-view.
1 parent 3272f4d commit 3f52014

File tree

6 files changed

+272
-69
lines changed

6 files changed

+272
-69
lines changed

lib/plan-builder.js

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ bldrgen.AccessPlan.prototype.col = function(...args) {
8181
class Builder extends bldrgen.PlanBuilder {
8282
constructor() {
8383
super({});
84-
bldrgen.rdt = (bldrgen.rdt !== void 0) ? bldrgen.rdt : new RdtExpr();
84+
if(this.rdt === void 0) {
85+
this.rdt = new RdtExpr();
86+
}
8587
}
88+
8689
prefixer(base) {
8790
const self = this;
8891

@@ -115,114 +118,96 @@ class RdtExpr {
115118
* Controls features such as the length and type of the generated value.
116119
* @method planBuilder#maskDeterministic
117120
* @since 2.7.0
118-
* @param { PlanColumnName } [column] - The name of the column to be defined.
119-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
120-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
121+
* @param args - Options for redacting.
121122
* @returns { planBuilder.PlanExprCol }
122123
*/
123-
maskDeterministic(column, options) {
124-
return redactimpl('maskDeterministic', 'mask-deterministic', column, options);
124+
maskDeterministic(...args) {
125+
return redactimpl('maskDeterministic', 'mask-deterministic',1,args);
125126
}
126127
/** This function replaces values with random text. The masking value can vary across repeated application to the same input value.
127128
* Controls the length of the generated value and type of replacement text (numbers or letters).
128129
* @method planBuilder#maskRandom
129130
* @since 2.7.0
130-
* @param { PlanColumnName } [column] - The name of the column to be defined.
131-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
132-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
131+
* @param args - Options for redacting.
133132
* @returns { planBuilder.PlanExprCol }
134133
*/
135-
maskRandom(column, options) {
136-
return redactimpl('maskRandom', 'mask-random', column, options);
134+
maskRandom(...args) {
135+
return redactimpl('maskRandom', 'mask-random', 1, args);
137136
}
138137
/** This function redacts data that matches the pattern of a dateTime value. Controls the expected input format and the masking dateTime format.
139138
* @method planBuilder#redactDatetime
140139
* @since 2.7.0
141-
* @param { PlanColumnName } [column] - The name of the column to be defined.
142-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
143-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
140+
* @param args - Options for redacting.
144141
* @returns { planBuilder.PlanExprCol }
145142
*/
146-
redactDatetime(column, options) {
147-
return redactimpl('redactDatetime', 'redact-datetime', column, options);
143+
redactDatetime(...args) {
144+
return redactimpl('redactDatetime', 'redact-datetime',2, args);
148145
}
149146
/** This function redacts data that matches the pattern of an email address.
150147
* Controls whether to mask the entire address, only the username, or only the domain name.
151148
* @method planBuilder#redactEmail
152149
* @since 2.7.0
153-
* @param { PlanColumnName } [column] - The name of the column to be defined.
154-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
155-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
150+
* @param args - Options for redacting.
156151
* @returns { planBuilder.PlanExprCol }
157152
*/
158-
redactEmail(column, options) {
159-
return redactimpl('redactEmail', 'redact-email', column, options);
153+
redactEmail(...args) {
154+
return redactimpl('redactEmail', 'redact-email', 1, args);
160155
}
161156
/** This function redacts data that matches the pattern of an IPv4 address. Controls what character to use as a masking character.
162157
* @method planBuilder#redactIpv4
163158
* @since 2.7.0
164-
* @param { PlanColumnName } [column] - The name of the column to be defined.
165-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
166-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
159+
* @param args - Options for redacting.
167160
* @returns { planBuilder.PlanExprCol }
168161
*/
169-
redactIpv4(column, options) {
170-
return redactimpl('redactIpv4', 'redact-ipv4', column, options);
162+
redactIpv4(...args) {
163+
return redactimpl('redactIpv4', 'redact-ipv4', 1, args);
171164
}
172165
/** This function replaces values with random numbers. Controls the data type, range, and format of the masking values.
173166
* @method planBuilder#redactNumber
174167
* @since 2.7.0
175-
* @param { PlanColumnName } [column] - The name of the column to be defined.
176-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
177-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
168+
* @param args - Options for redacting.
178169
* @returns { planBuilder.PlanExprCol }
179170
*/
180-
redactNumber(column, options) {
181-
return redactimpl('redactNumber', 'redact-number', column, options);
171+
redactNumber(...args) {
172+
return redactimpl('redactNumber', 'redact-number', 1, args);
182173
}
183174
/** This function redacts data that matches a given regular expression. You must specify the regular expression and the masking text.
184175
* @method planBuilder#redactRegex
185176
* @since 2.7.0
186-
* @param { PlanColumnName } [column] - The name of the column to be defined.
187-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
188-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
177+
* @param args - Options for redacting.
189178
* @returns { planBuilder.PlanExprCol }
190179
*/
191-
redactRegex(column, options) {
192-
return redactimpl('redactRegex', 'redact-regex', column, options);
180+
redactRegex(...args) {
181+
return redactimpl('redactRegex', 'redact-regex', 2, args);
193182
}
194183
/** This function redacts data that matches the pattern of a US Social Security Number (SSN).
195184
* Controls whether or not to preserve the last 4 digits and what character to use as a masking character.
196185
* @method planBuilder#redactUsSsn
197186
* @since 2.7.0
198-
* @param { PlanColumnName } [column] - The name of the column to be defined.
199-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
200-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
187+
* @param args - Options for redacting.
201188
* @returns { planBuilder.PlanExprCol }
202189
*/
203-
redactUsSsn(column, options) {
204-
return redactimpl('redactUsSsn', 'redact-us-ssn', column, options);
190+
redactUsSsn(...args) {
191+
return redactimpl('redactUsSsn', 'redact-us-ssn', 1, args);
205192
}
206193
/** This function redacts data that matches the pattern of a US telephone number.
207194
* Controls whether or not to preserve the last 4 digits and what character to use as a masking character.
208195
* @method planBuilder#redactUsPhone
209196
* @since 2.7.0
210-
* @param { PlanColumnName } [column] - The name of the column to be defined.
211-
* This can be either a string or the return value from PlanBuilder.col(), PlanBuilder.viewCol() or PlanBuilder.schemaCol().
212-
* @param { Item } [options] - An object with name-value pairs specific to the redaction method.
197+
* @param args - Options for redacting.
213198
* @returns { planBuilder.PlanExprCol }
214199
*/
215-
redactUsPhone(column, options) {
216-
return redactimpl('redactUsPhone', 'redact-us-phone', column, options);
200+
redactUsPhone(...args) {
201+
return redactimpl('redactUsPhone', 'redact-us-phone', 1, args);
217202
}
218203
}
219204

220-
function redactimpl(clientName, serverName, column, options) {
221-
const namer = bldrbase.getNamer(options, 'column');
205+
function redactimpl(clientName, serverName, minArity, args) {
206+
const namer = bldrbase.getNamer(args, 'column');
222207
const paramdefs = [['column', [bldrgen.PlanColumn, types.XsString], true, false], ['option', [], false, false]];
223208
const checkedArgs = (namer !== null) ?
224-
bldrbase.makeNamedArgs(namer, `PlanBuilder.${clientName}`, 2, new Set(['column', 'expression']), paramdefs, options) :
225-
bldrbase.makePositionalArgs(`PlanBuilder.${clientName}`, 2, false, paramdefs, options);
209+
bldrbase.makeNamedArgs(namer, `PlanBuilder.${clientName}`, minArity, new Set(['column', 'options']), paramdefs, args) :
210+
bldrbase.makePositionalArgs(`PlanBuilder.${clientName}`, minArity, false, paramdefs, args);
226211
return new bldrgen.PlanExprCol('ordt', serverName, checkedArgs);
227212
}
228213

lib/rows.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,9 @@ Rows.prototype.generateView = function generateViewRows(builtPlan, schema, view,
378378
'Accept': acceptHeader
379379
};
380380

381-
requestOptions.path = '/v1/rows?output=generateView';
381+
const endpoint = '/v1/rows?output=generateView&schemaName='+schema+'&viewName='+view;
382+
requestOptions.path = mlutil.databaseParam(connectionParams, endpoint, '&');
383+
382384

383385
const operation = new Operation(
384386
'generate view', this.client, requestOptions, 'single', 'single');

test-basic/endpoint-caller.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ describe('Endpoint caller', function() {
3535
done();
3636
})
3737
.catch(err => {
38-
expect.fail(err.toString());
39-
done();
38+
done(err);
4039
});
4140
});
4241

@@ -53,8 +52,7 @@ describe('Endpoint caller', function() {
5352
done();
5453
})
5554
.catch(err => {
56-
expect.fail(err.toString());
57-
done();
55+
done(err);
5856
});
5957
});
6058

@@ -73,8 +71,7 @@ describe('Endpoint caller', function() {
7371
done();
7472
})
7573
.catch(err => {
76-
expect.fail(err.toString());
77-
done();
74+
done(err);
7875
});
7976
});
8077

@@ -93,8 +90,7 @@ describe('Endpoint caller', function() {
9390
done();
9491
})
9592
.catch(err => {
96-
expect.fail(err.toString());
97-
done();
93+
done(err);
9894
});
9995
});
10096
});

test-basic/plan-processors.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,17 @@ describe('processor', function() {
327327
);}, Error, 'schema cannot be null or empty');
328328
done();
329329
});
330+
it('generateView with literals', function(done) {
331+
generateView(
332+
p.fromLiterals([
333+
{id:1, val: 2},
334+
{id:2, val: 4}
335+
]),
336+
'opticUnitTest', 'musicianView'
337+
).then(function(output) {
338+
should.exist(output);
339+
done();
340+
})
341+
.catch(err => {console.log(err); done(err);});
342+
});
330343
});

0 commit comments

Comments
 (0)