UI: Mount tune fix (#4431)

* serialize instead of toJSON when mount tuning

* add tests

* remove model unit test

* fix typo
This commit is contained in:
Matthew Irish 2018-04-23 15:32:43 -05:00 committed by GitHub
parent 3e6a9d5e09
commit ca872c5de1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 5 deletions

View File

@ -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);

View File

@ -6,7 +6,7 @@
value={{time}}
id="time-{{elementId}}"
type="text"
name="time"
name="time-{{elementId}}"
class="input"
oninput={{action 'changedValue' 'time'}}
/>
@ -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|}}

View File

@ -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) {
@ -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.`,

View File

@ -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);
});
});

View File

@ -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]'),
};

View File

@ -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);