implement identity too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-10-08 22:49:42 +02:00
parent 811ff0cddc
commit b52715bc2e
27 changed files with 396 additions and 288 deletions
+5 -10
View File
@@ -14,9 +14,8 @@
* limitations under the License.
*/
import { BackstageUserIdentity, IdentityApi } from '@backstage/core-plugin-api';
import { VisitsStorageApi } from './VisitsStorageApi';
import { MockStorageApi } from '@backstage/test-utils';
import { MockStorageApi, mockApis } from '@backstage/test-utils';
import { Visit, VisitsApi } from './VisitsApi';
describe('VisitsStorageApi.create', () => {
@@ -26,13 +25,9 @@ describe('VisitsStorageApi.create', () => {
() => Math.floor(Math.random() * 16).toString(16), // 0x0 to 0xf
) as `${string}-${string}-${string}-${string}-${string}`;
const mockIdentityApi: IdentityApi = {
signOut: jest.fn(),
getProfileInfo: jest.fn(),
getBackstageIdentity: async () =>
({ userEntityRef: 'user:default/guest' } as BackstageUserIdentity),
getCredentials: jest.fn(),
};
const mockIdentityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
});
beforeEach(() => {
window.crypto.randomUUID = mockRandomUUID;
@@ -40,7 +35,7 @@ describe('VisitsStorageApi.create', () => {
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
jest.useRealTimers();
window.localStorage.clear();
});
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { BackstageUserIdentity, IdentityApi } from '@backstage/core-plugin-api';
import { mockApis } from '@backstage/test-utils';
import { VisitsWebStorageApi } from './VisitsWebStorageApi';
describe('VisitsWebStorageApi.create()', () => {
@@ -24,13 +24,9 @@ describe('VisitsWebStorageApi.create()', () => {
() => Math.floor(Math.random() * 16).toString(16), // 0x0 to 0xf
) as `${string}-${string}-${string}-${string}-${string}`;
const mockIdentityApi: IdentityApi = {
signOut: jest.fn(),
getProfileInfo: jest.fn(),
getBackstageIdentity: async () =>
({ userEntityRef: 'user:default/guest' } as BackstageUserIdentity),
getCredentials: jest.fn(),
};
const mockIdentityApi = mockApis.identity({
userEntityRef: 'user:default/guest',
});
const mockErrorApi = { post: jest.fn(), error$: jest.fn() };
@@ -40,7 +36,7 @@ describe('VisitsWebStorageApi.create()', () => {
afterEach(() => {
window.localStorage.clear();
jest.resetAllMocks();
jest.clearAllMocks();
});
it('instantiates with only identitiyApi', () => {