Skip to content

Commit

Permalink
rename propagateErrors -> includeErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
nataly87s committed Apr 7, 2019
1 parent c6d98f7 commit 5cc7b38
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
Expand Up @@ -4,7 +4,7 @@ const client = require('../../../utils/client');
describe('tweek api - propagate errors', () => {
const identityType = 'user';
const identityId = 'bad_context_user';
const url = `/api/v2/values/integration_tests/propagate_errors`;
const url = `/api/v2/values/integration_tests/include_errors`;

before(async () => {
await client
Expand All @@ -13,88 +13,84 @@ describe('tweek api - propagate errors', () => {
.expect(200);
});

describe('[propagateErrors = true]', () => {
describe('[includeErrors = true]', () => {
it('should return null on single key error', async () => {
const result = await client
.get(`${url}?${identityType}=${identityId}&$propagateErrors=true`)
.get(`${url}?${identityType}=${identityId}&$includeErrors=true`)
.expect('X-Error-Count', '1')
.expect(200);
expect(result.body).to.eql({
data: null,
errors: {
'integration_tests/propagate_errors': 'non matching types',
'integration_tests/include_errors': 'non matching types',
},
});
});

it('should return correct value if no error', async () => {
const result = await client
.get(`${url}?$propagateErrors=true`)
.get(`${url}?$includeErrors=true`)
.expect('X-Error-Count', '0')
.expect(200);
expect(result.body).to.eql({ data: 'DefaultValue', errors: {} });
});

it('should skip error key on scan', async () => {
const result = await client
.get(
`/api/v2/values/integration_tests/_?${identityType}=${identityId}&$propagateErrors=true`,
)
.get(`/api/v2/values/integration_tests/_?${identityType}=${identityId}&$includeErrors=true`)
.expect('X-Error-Count', '1')
.expect(200);

expect(result.body.data).to.not.have.property('propagate_errors');
expect(result.body.data).to.not.have.property('include_errors');
expect(result.body.errors).to.eql({
'integration_tests/propagate_errors': 'non matching types',
'integration_tests/include_errors': 'non matching types',
});
});

it('should return correct value if no error in scan', async () => {
const result = await client
.get(`/api/v2/values/integration_tests/_?$propagateErrors=true`)
.get(`/api/v2/values/integration_tests/_?$includeErrors=true`)
.expect('X-Error-Count', '0')
.expect(200);

expect(result.body.data).to.deep.include({ propagate_errors: 'DefaultValue' });
expect(result.body.data).to.deep.include({ include_errors: 'DefaultValue' });
expect(result.body.errors).to.eql({});
});
});

describe('[propagateErrors = false]', () => {
describe('[includeErrors = false]', () => {
it('should return null on single key error', async () => {
const result = await client
.get(`${url}?${identityType}=${identityId}&$propagateErrors=false`)
.get(`${url}?${identityType}=${identityId}&$includeErrors=false`)
.expect('X-Error-Count', '1')
.expect(200);
expect(result.body).to.eql(null);
});

it('should return correct value if no error', async () => {
const result = await client
.get(`${url}?$propagateErrors=false`)
.get(`${url}?$includeErrors=false`)
.expect('X-Error-Count', '0')
.expect(200);
expect(result.body).to.eql('DefaultValue');
});

it('should skip error key on scan', async () => {
const result = await client
.get(
`/api/v2/values/integration_tests/_?${identityType}=${identityId}&$propagateErrors=true`,
)
.get(`/api/v2/values/integration_tests/_?${identityType}=${identityId}&$includeErrors=true`)
.expect('X-Error-Count', '1')
.expect(200);

expect(result.body).to.not.have.property('propagate_errors');
expect(result.body).to.not.have.property('include_errors');
});

it('should return correct value if no error in scan', async () => {
const result = await client
.get(`/api/v2/values/integration_tests/_?$propagateErrors=false`)
.get(`/api/v2/values/integration_tests/_?$includeErrors=false`)
.expect('X-Error-Count', '0')
.expect(200);

expect(result.body).to.deep.include({ propagate_errors: 'DefaultValue' });
expect(result.body).to.deep.include({ include_errors: 'DefaultValue' });
});
});
});
10 changes: 5 additions & 5 deletions services/api/Tweek.ApiService/Controllers/KeysController.cs
Expand Up @@ -75,8 +75,8 @@ private static ConfigurationPath[] GetQuery(ConfigurationPath path, string[] inc
[Produces("application/json")]
[ProducesResponseType(typeof(object), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(void), (int)HttpStatusCode.Forbidden)]
public async Task<ActionResult> GetAsyncSwagger([FromQuery] string keyPath,
[FromQuery( Name = "$flatten")] bool flatten = false,
public async Task<ActionResult> GetAsyncSwagger([FromQuery] string keyPath,
[FromQuery( Name = "$flatten")] bool flatten = false,
[FromQuery( Name = "$include")] List<string> includeKeys = null)
{
if (System.String.IsNullOrWhiteSpace(keyPath)) return BadRequest("Missing key path");
Expand All @@ -93,7 +93,7 @@ public async Task<ActionResult> GetAsync([FromRoute] string path)
var allParams = PartitionByKey(HttpContext.Request.Query.ToDictionary(x => x.Key, x => x.Value), x => x.StartsWith("$"));
var modifiers = allParams.Item1;
var isFlatten = modifiers.TryGetValue("$flatten").Select(x => bool.Parse(x.First())).IfNone(false);
var propagateErrors = modifiers.TryGetValue("$propagateErrors").Select(x => bool.Parse(x.First())).IfNone(false);
var includeErrors = modifiers.TryGetValue("$includeErrors").Select(x => bool.Parse(x.First())).IfNone(false);
var ignoreKeyTypes = modifiers.TryGetValue("$ignoreKeyTypes").Select(x => bool.Parse(x.First())).IfNone(false);
var includePaths = modifiers.TryGetValue("$include").Select(x => x.ToArray()).IfNone(new string[] {});

Expand Down Expand Up @@ -125,9 +125,9 @@ public async Task<ActionResult> GetAsync([FromRoute] string path)
else if (values.Data.TryGetValue(root, out var value))
{
result = ignoreKeyTypes ? TranslateValueToString(value) : value.Value;
}
}

if (!propagateErrors)
if (!includeErrors)
{
return Json(result);
}
Expand Down
@@ -1,7 +1,7 @@
{
"key_path": "integration_tests/propagate_errors",
"key_path": "integration_tests/include_errors",
"meta": {
"name": "integration_tests/propagate_errors",
"name": "integration_tests/include_errors",
"description": "",
"tags": [],
"readOnly": false,
Expand Down

0 comments on commit 5cc7b38

Please sign in to comment.