Skip to content

Commit

Permalink
UI: Mount tune fix (#4431)
Browse files Browse the repository at this point in the history
* serialize instead of toJSON when mount tuning

* add tests

* remove model unit test

* fix typo
  • Loading branch information
meirish authored and truenorthcreative committed Apr 23, 2018
1 parent d4bcb38 commit f4a908b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/auth-config-form/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DS from 'ember-data';
export default AuthConfigComponent.extend({
saveModel: task(function*() {
const model = this.get('model');
let data = model.get('config').toJSON();
let data = model.get('config').serialize();
data.description = model.get('description');
try {
yield model.tune(data);
Expand Down
6 changes: 3 additions & 3 deletions ui/app/templates/components/ttl-picker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
value={{time}}
id="time-{{elementId}}"
type="text"
name="time"
name="time-{{elementId}}"
class="input"
oninput={{action 'changedValue' 'time'}}
/>
Expand All @@ -15,8 +15,8 @@
<div class="select is-fullwidth">
<select
data-test-ttl-unit
name="unit"
id="unit"
name="unit-{{elementId}}"
id="unit-{{elementId}}"
onchange={{action 'changedValue' 'unit'}}
>
{{#each unitOptions as |unitOption|}}
Expand Down
10 changes: 10 additions & 0 deletions ui/tests/acceptance/settings/auth/configure/section-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@ import { test } from 'qunit';
import moduleForAcceptance from 'vault/tests/helpers/module-for-acceptance';
import enablePage from 'vault/tests/pages/settings/auth/enable';
import page from 'vault/tests/pages/settings/auth/configure/section';
import apiStub from 'vault/tests/helpers/noop-all-api-requests';

moduleForAcceptance('Acceptance | settings/auth/configure/section', {
beforeEach() {
this.server = apiStub({ usePassthrough: true });
return authLogin();
},
afterEach() {
this.server.shutdown();
},
});

test('it can save options', function(assert) {
Expand All @@ -20,6 +25,11 @@ test('it can save options', function(assert) {
page.save();
});
andThen(() => {
let tuneRequest = this.server.passthroughRequests.filterBy('url', `/v1/sys/mounts/auth/${path}/tune`)[0];
let keys = Object.keys(JSON.parse(tuneRequest.requestBody));
assert.ok(keys.includes('default_lease_ttl'), 'passes default_lease_ttl on tune');
assert.ok(keys.includes('max_lease_ttl'), 'passes max_lease_ttl on tune');

assert.equal(
page.flash.latestMessage,
`The configuration options were saved successfully.`,
Expand Down
42 changes: 42 additions & 0 deletions ui/tests/integration/components/auth-config-form/options-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { moduleForComponent, test } from 'ember-qunit';
import Ember from 'ember';
import wait from 'ember-test-helpers/wait';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';

import { create } from 'ember-cli-page-object';
import authConfigForm from 'vault/tests/pages/components/auth-config-form/options';

const component = create(authConfigForm);

moduleForComponent('auth-config-form/options', 'Integration | Component | auth-config-form options', {
integration: true,
beforeEach() {
Ember.getOwner(this).lookup('service:flash-messages').registerTypes(['success']);
component.setContext(this);
},

afterEach() {
component.removeContext();
},
});

test('it submits data correctly', function(assert) {
let model = Ember.Object.create({
tune() {
return Ember.RSVP.resolve();
},
config: {
serialize() {
return {};
},
},
});
sinon.spy(model.config, 'serialize');
this.set('model', model);
this.render(hbs`{{auth-config-form/options model=model}}`);
component.save();
wait().then(() => {
assert.ok(model.config.serialize.calledOnce);
});
});
9 changes: 9 additions & 0 deletions ui/tests/pages/components/auth-config-form/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { clickable, fillable } from 'ember-cli-page-object';

import fields from '../form-field';
export default {
...fields,
ttlValue: fillable('[data-test-ttl-value]'),
ttlUnit: fillable('[data-test-ttl-value]'),
save: clickable('[data-test-save-config]'),
};
2 changes: 1 addition & 1 deletion ui/tests/pages/components/form-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default {
// we use name in the label `for` attribute
// this is consistent across all types of fields
//(otherwise we'd have to use name on select or input or textarea)
return this.toArray().findBy('for', name);
return this.filterBy('for', name)[0];
},
fillIn(name, value) {
return this.findByName(name).input(value);
Expand Down

0 comments on commit f4a908b

Please sign in to comment.