import { TestBed } from '@angular/core/testing';
import { AppState } from '@app/core';
import { Store, StoreModule } from '@ngrx/store';
import { MockStore, provideMockStore } from '../../../testing/utils';
import { AuthGuardService } from './auth-guard.service';
import { AuthState } from './auth.models';

describe('AuthGuardService', () => {
  let authGuardService: AuthGuardService;
  let store: MockStore<AppState>;

  const authState: AuthState = {
    isAuthenticated: true
  };

  const state = createState(authState);

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [StoreModule.forRoot({})],
      providers: [AuthGuardService, provideMockStore()]
    });
    authGuardService = TestBed.get(AuthGuardService);
    store = TestBed.get(Store);
    store.setState(state);
  });

  it('should be created', () => {
    expect(authGuardService).toBeTruthy();
  });

  it('should return isAuthenticated from authState', () => {
    authGuardService.canActivate().subscribe(canActivate => {
      expect(canActivate).toBe(state.auth.isAuthenticated);
    });
  });
});

function createState(authState: AuthState) {
  return {
    auth: authState
  };
}

import { TestBed } from '@angular/core/testing';
import { AppState } from '@app/core';
import { Store, StoreModule } from '@ngrx/store';
import { MockStore, provideMockStore } from '@testing/utils';
import { AuthGuardService } from './auth-guard.service';
import { AuthState } from './auth.models';

describe('AuthGuardService', () => {
  let authGuardService: AuthGuardService;
  let store: MockStore<AppState>;

  const authState: AuthState = {
    isAuthenticated: true
  };

  const state = createState(authState);

  beforeEach(() => {
    TestBed.configureTestingModule({
      imports: [StoreModule.forRoot({})],
      providers: [AuthGuardService, provideMockStore()]
    });
    authGuardService = TestBed.get(AuthGuardService);
    store = TestBed.get(Store);
    store.setState(state);
  });

  it('should be created', () => {
    expect(authGuardService).toBeTruthy();
  });

  it('should return isAuthenticated from authState', () => {
    authGuardService.canActivate().subscribe(canActivate => {
      expect(canActivate).toBe(state.auth.isAuthenticated);
    });
  });
});

function createState(authState: AuthState) {
  return {
    auth: authState
  };
}

Optimize import paths for testing utils
test(auth): Optimize import paths for testing utils
