-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: π add missing controller unit tests in admin-ui (#2553)
* test: π add missing controller unit tests in admin-ui β Closes: https://hashicorp.atlassian.net/browse/ICU-14740
- Loading branch information
1 parent
7c18141
commit 57568f9
Showing
77 changed files
with
946 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
ui/admin/tests/unit/controllers/account/change-password-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) HashiCorp, Inc. | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
import { module, test } from 'qunit'; | ||
import { setupTest } from 'ember-qunit'; | ||
import { visit } from '@ember/test-helpers'; | ||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage'; | ||
import { authenticateSession } from 'ember-simple-auth/test-support'; | ||
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method'; | ||
|
||
module('Unit | Controller | account/change-password', function (hooks) { | ||
setupTest(hooks); | ||
setupMirage(hooks); | ||
|
||
let controller; | ||
let store; | ||
|
||
const instances = { | ||
scopes: { | ||
global: null, | ||
}, | ||
authMethod: null, | ||
account: null, | ||
}; | ||
|
||
const urls = { | ||
globalScope: null, | ||
}; | ||
|
||
hooks.beforeEach(async function () { | ||
authenticateSession({}); | ||
controller = this.owner.lookup('controller:account/change-password'); | ||
store = this.owner.lookup('service:store'); | ||
|
||
instances.scopes.global = this.server.create('scope', { | ||
id: 'global', | ||
type: 'global', | ||
}); | ||
instances.authMethod = this.server.create('auth-method', { | ||
scope: instances.scopes.global, | ||
type: TYPE_AUTH_METHOD_PASSWORD, | ||
}); | ||
instances.account = this.server.create('account', { | ||
scope: instances.scopes.global, | ||
authMethod: instances.authMethod, | ||
}); | ||
|
||
urls.globalScope = `/scopes/global`; | ||
}); | ||
|
||
test('it exists', function (assert) { | ||
assert.ok(controller); | ||
}); | ||
|
||
test('changePassword action makes the correct API call with correct values', async function (assert) { | ||
assert.expect(2); | ||
const password = 'current password'; | ||
const newPassword = 'new password'; | ||
this.server.post( | ||
'/accounts/:idMethod', | ||
(_, { params: { idMethod }, requestBody }) => { | ||
const attrs = JSON.parse(requestBody); | ||
assert.strictEqual(attrs.current_password, password); | ||
assert.strictEqual(attrs.new_password, newPassword); | ||
const id = idMethod.split(':')[0]; | ||
return { id }; | ||
}, | ||
); | ||
await visit(urls.globalScope); | ||
const account = await store.findRecord('account', instances.account.id); | ||
|
||
await controller.changePassword(account, password, newPassword); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.