Skip to content

Commit

Permalink
it works except 1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
buffet-time committed Aug 20, 2024
1 parent fd0d83e commit 090b2cf
Show file tree
Hide file tree
Showing 44 changed files with 118 additions and 223 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script setup lang="ts">
import { ref, computed } from 'vue'
import BaseButton from 'elements/buttons/BaseButton/BaseButton.vue'
import { useResendAccountConfirmation } from '~/composables/api'
import { useCurrentUser, useI18n, useModalAlert } from '#imports'
const currentUser = await useCurrentUser()
const errorText = ref('')
Expand Down Expand Up @@ -69,3 +71,5 @@ async function resend() {
@apply text-red-600;
}
</style>
import { useCurrentUser, useModalAlert, useI18n } from '#imports'; import {
useResendAccountConfirmation } from '~/composables/api';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
import { useI18n } from '#imports'
import type { ComputedRef } from 'vue'
// import { type LocaleObject } from '#imports'
Expand Down
1 change: 1 addition & 0 deletions components/blocks/cards/BasicAlert/BasicAlert.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { getByClass, getByTestId, getHTMLElement } from 'root/testUtils'
import BasicAlert from './BasicAlert.vue'
import { useModalAlert } from '#imports'

beforeEach(() => {
const { state: modalAlertState } = useModalAlert()
Expand Down
1 change: 1 addition & 0 deletions components/blocks/cards/BasicAlert/BasicAlert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import CloseButton from 'elements/buttons/CloseButton/CloseButton.vue'
import Card from 'elements/cards/Card/Card.vue'
import CardHeader from 'elements/cards/CardHeader/CardHeader.vue'
import CardBody from 'elements/cards/CardBody/CardBody.vue'
import { useModalAlert } from '#imports'
const { closeAlert, state } = useModalAlert()
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@ import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import { getByTestId } from 'root/testUtils'
import ForgotPasswordCard from './ForgotPasswordCard.vue'
import type { RecoverAccountRequest } from 'lib/api/data-contracts'

Check warning on line 4 in components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts

View workflow job for this annotation

GitHub Actions / build_and_lint

'RecoverAccountRequest' is defined but never used. Allowed unused vars must match /^_/u
import type { optionalParameters } from '~/composables/useApi'

Check warning on line 5 in components/blocks/cards/ForgotPasswordCard/ForgotPasswordCard.test.ts

View workflow job for this annotation

GitHub Actions / build_and_lint

'optionalParameters' is defined but never used. Allowed unused vars must match /^_/u

mockNuxtImport('useRecoverAccount', () => {
return async (
_requestData: RecoverAccountRequest,
opts: optionalParameters<void> = {},
) => {
const { onOkay } = opts
if (onOkay) {
await onOkay()
vi.mock(
import('~/composables/api/useRecoverAccount'),
async (importOriginal) => {
const mod = await importOriginal()

return {
...mod,
// replace some exports
onOkay: vi.fn(),
}
}
})
},
)

// mockNuxtImport('useRecoverAccount', () => {
// return async (
// _requestData: RecoverAccountRequest,
// opts: optionalParameters<void> = {},
// ) => {
// const { onOkay } = opts
// if (onOkay) {
// await onOkay()
// }
// }
// })

afterAll(() => {
vi.restoreAllMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import CardBody from 'elements/cards/CardBody/CardBody.vue'
import CardHeader from 'elements/cards/CardHeader/CardHeader.vue'
import BaseInput from 'elements/inputs/BaseInput/BaseInput.vue'
import { isEmailValid, isUsernameValid } from 'lib/form_helpers'
import { useModalAlert } from '#imports'
import { useRecoverAccount } from '~/composables/api'
interface ForgotPasswordCardPops {
modal?: boolean
Expand All @@ -21,7 +23,7 @@ const emit = defineEmits<{
(event: 'close' | 'cancelClick'): void
}>()
const props = withDefaults(defineProps<ForgotPasswordCardPops>(), {
withDefaults(defineProps<ForgotPasswordCardPops>(), {
modal: false,
})
Expand Down Expand Up @@ -76,7 +78,7 @@ function resetPassword() {
<CardHeader class="forgot-password-card__header">
<div class="forgot-password-card__title">Forgot Password</div>
<CloseButton
v-show="props.modal"
v-show="modal"
data-testid="close-button"
@click.prevent="emit('close')"
/>
Expand Down
5 changes: 3 additions & 2 deletions components/blocks/cards/LogInCard/LogInCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CardBody from 'elements/cards/CardBody/CardBody.vue'
import CardHeader from 'elements/cards/CardHeader/CardHeader.vue'
import Card from 'elements/cards/Card/Card.vue'
import HideShowPassword from 'elements/buttons/HideShowPassword/HideShowPassword.vue'
import { useLoginUser } from '~/composables/api'
interface LogInCardProps {
modal?: boolean
Expand All @@ -23,7 +24,7 @@ const emit = defineEmits<{
(event: 'close' | 'forgotPasswordClick' | 'signUpClick'): void
}>()
const props = withDefaults(defineProps<LogInCardProps>(), {
withDefaults(defineProps<LogInCardProps>(), {
modal: false,
})
Expand Down Expand Up @@ -72,7 +73,7 @@ async function login() {
</BaseButton>

<CloseButton
v-show="props.modal"
v-show="modal"
data-testid="close-button"
@click.prevent="emit('close')"
/>
Expand Down
1 change: 1 addition & 0 deletions components/blocks/cards/SignUpCard/SignUpCard.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { getByTestId, getHTMLElement } from 'root/testUtils'
import SignUpCard from './SignUpCard.vue'
import { useRuntimeConfig } from '#imports'

afterEach(() => {
fetchMock.resetMocks()
Expand Down
5 changes: 3 additions & 2 deletions components/blocks/cards/SignUpCard/SignUpCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import CloseButton from 'elements/buttons/CloseButton/CloseButton.vue'
import Card from 'elements/cards/Card/Card.vue'
import CardHeader from 'elements/cards/CardHeader/CardHeader.vue'
import CardBody from 'elements/cards/CardBody/CardBody.vue'
import { useLoginUser, useRegisterUser } from '~/composables/api'
interface SignUpCardProps {
modal?: boolean
Expand All @@ -31,7 +32,7 @@ const emit = defineEmits<{
(event: 'close' | 'logInClick' | 'signUpClick'): void
}>()
const props = withDefaults(defineProps<SignUpCardProps>(), {
withDefaults(defineProps<SignUpCardProps>(), {
modal: false,
})
Expand Down Expand Up @@ -124,7 +125,7 @@ function validatePasswordInputs() {
<div class="signup-card__title">Sign Up</div>

<CloseButton
v-show="props.modal"
v-show="modal"
data-testid="close-button"
@click.prevent="emit('close')"
/>
Expand Down
1 change: 1 addition & 0 deletions components/blocks/nav/SiteNavbar/SiteNavbar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mountSuspended } from '@nuxt/test-utils/runtime'
import * as apiComposables from 'composables/api'
import { getByTestId } from 'root/testUtils'
import SiteNavbar from './SiteNavbar.vue'
import { useSessionToken } from '#imports'

afterEach(() => {
vi.restoreAllMocks()
Expand Down
2 changes: 2 additions & 0 deletions components/blocks/nav/SiteNavbar/SiteNavbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import LogInCard from 'blocks/cards/LogInCard/LogInCard.vue'
import SignUpCard from 'blocks/cards/SignUpCard/SignUpCard.vue'
import BaseModal from 'elements/modals/BaseModal/BaseModal.vue'
import SearchBar from 'blocks/SearchBar/SearchBar.vue'
import { useSessionToken } from '#imports'
import { useLogoutUser } from '~/composables/api'
interface NavbarState {
mobileNavIsActive: boolean
Expand Down
2 changes: 1 addition & 1 deletion components/elements/buttons/Dropdown/Dropdown.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { provide, ref } from 'vue'
import { provide, ref, type Ref } from 'vue'
import BaseButton from '../BaseButton/BaseButton.vue'
export interface SharedState {
Expand Down
2 changes: 1 addition & 1 deletion components/elements/buttons/Dropdown/DropdownItem.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { inject } from 'vue'
import { inject, ref } from 'vue'
import type { SharedState } from './Dropdown.vue'
const emit = defineEmits<{
Expand Down
1 change: 1 addition & 0 deletions composables/api/useChangePassword/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRuntimeConfig } from '#imports'
import {
type ApiResponse,
type optionalParameters,
Expand Down
2 changes: 2 additions & 0 deletions composables/api/useChangePassword/useChangePassword.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useChangePassword from '.'

const mockSuccessRecoverCreate2 = vi.fn(() => Promise.resolve({ ok: true }))

describe('useChangePassword', () => {
Expand Down
1 change: 1 addition & 0 deletions composables/api/useConfirmAccount/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRuntimeConfig } from '#imports'
import {
type ApiResponse,
type optionalParameters,
Expand Down
2 changes: 2 additions & 0 deletions composables/api/useConfirmAccount/useConfirmAccount.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useConfirmAccount from '.'

const mockSuccessAccountConfirmation = vi.fn(() =>
Promise.resolve({ ok: true }),
)
Expand Down
1 change: 1 addition & 0 deletions composables/api/useGetLeaderboardDetail/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'composables/useApi'
import { Leaderboards } from 'lib/api/Leaderboards'
import type { LeaderboardViewModel } from 'lib/api/data-contracts'
import { useRuntimeConfig } from '#imports'

export async function useGetLeaderboardDetail(
leaderboardSlug: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useGetLeaderboardDetail from '.'

const mockSuccessLeaderboardsDetail = vi.fn(() => Promise.resolve({ ok: true }))

describe('useGetLeaderboardDetail', () => {
Expand Down
7 changes: 6 additions & 1 deletion composables/api/useGetUserDetail/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ApiResponse, optionalParameters } from 'composables/useApi'
import { useRuntimeConfig } from '#imports'
import {
useApi,
type ApiResponse,
type optionalParameters,
} from 'composables/useApi'
import { Users } from 'lib/api/Users'
import type { UserViewModel } from 'lib/api/data-contracts'

Expand Down
2 changes: 2 additions & 0 deletions composables/api/useGetUserDetail/useGetUserDetail.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useGetUserDetail from '.'

const mockSuccessUsersDetail = vi.fn(() => Promise.resolve({ ok: true }))

describe('useGetUserDetail', () => {
Expand Down
1 change: 1 addition & 0 deletions composables/api/useLoginUser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSessionToken, useRuntimeConfig } from '#imports'
import {
type ApiResponse,
type optionalParameters,
Expand Down
3 changes: 3 additions & 0 deletions composables/api/useLoginUser/useLoginUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { useSessionToken } from '#imports'
import useLoginUser from '.'

// const mockFailureUsersLoginCreate = vi.fn(() => Promise.resolve({ ok: false }))
const mockSuccessAccountLoginCreate = vi.fn(() =>
Promise.resolve({ data: { token: 'token' }, ok: true }),
Expand Down
2 changes: 2 additions & 0 deletions composables/api/useLogoutUser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useSessionToken } from '#imports'

export default function useLogoutUser() {
useSessionToken().value = ''
}
2 changes: 2 additions & 0 deletions composables/api/useLogoutUser/useLogoutUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useCurrentUser, useSessionToken } from '#imports'
import type { UserViewModel } from 'lib/api/data-contracts'
import useLogoutUser from '.'

const token = 'auth-token'
const user: UserViewModel = {
Expand Down
7 changes: 6 additions & 1 deletion composables/api/useRecoverAccount/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Account } from 'lib/api/Account'
import type { ApiResponse, optionalParameters } from 'composables/useApi'
import {
useApi,
type ApiResponse,
type optionalParameters,
} from 'composables/useApi'
import type { RecoverAccountRequest } from 'lib/api/data-contracts'
import { useRuntimeConfig } from '#imports'

export async function useRecoverAccount(
requestData: RecoverAccountRequest,
Expand Down
2 changes: 2 additions & 0 deletions composables/api/useRecoverAccount/useRecoverAccount.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useRecoverAccount from '.'

const mockSuccessRecoverCreate = vi.fn(() => Promise.resolve({ ok: true }))

describe('useRecoverAccount', () => {
Expand Down
1 change: 1 addition & 0 deletions composables/api/useRegisterUser/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRuntimeConfig } from '#imports'
import {
type ApiResponse,
type optionalParameters,
Expand Down
2 changes: 2 additions & 0 deletions composables/api/useRegisterUser/useRegisterUser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useRegisterUser from '.'

const mockSuccessRegisterCreate = vi.fn(() => Promise.resolve({ ok: true }))

describe('useRegisterUser', () => {
Expand Down
1 change: 1 addition & 0 deletions composables/api/useResendAccountConfirmation/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useRuntimeConfig, useSessionToken } from '#imports'
import {
useApi,
type ApiResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import useResendAccountConfirmation from '.'
import useLoginUser from '../useLoginUser'

const mockSuccessLogin = vi.fn(() =>
Promise.resolve({ data: { token: 'token' }, ok: true }),
)
Expand Down
7 changes: 6 additions & 1 deletion composables/api/useValidateRecoveryToken/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { ApiResponse, optionalParameters } from 'composables/useApi'
import { useRuntimeConfig } from '#app'
import {
useApi,
type ApiResponse,
type optionalParameters,
} from 'composables/useApi'
import { Account } from 'lib/api/Account'

export async function useValidateRecoveryToken(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import useValidateRecoveryToken from '.'

const mockSuccessRecoverDetail = vi.fn(() => Promise.resolve({ ok: true }))

describe('useValidateRecoveryToken', () => {
Expand Down
1 change: 1 addition & 0 deletions composables/useApi/useApi.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ref } from 'vue'
import type { ProblemDetails } from 'lib/api/data-contracts'
import type { HttpResponse } from 'lib/api/http-client'
import useApi from '.'

interface Opts {
data?: object
Expand Down
2 changes: 2 additions & 0 deletions composables/useCurrentUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useAsyncData, useRuntimeConfig, useSessionToken } from '#imports'
import { Users } from 'lib/api/Users'
import type { UserViewModel } from 'lib/api/data-contracts'
import useApi from './useApi'

export default function useCurrentUser() {
return useAsyncData<Partial<UserViewModel>>(
Expand Down
2 changes: 2 additions & 0 deletions composables/useModalAlert.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useState } from '#imports'

interface ModalAlertState {
body: string
show: boolean
Expand Down
2 changes: 2 additions & 0 deletions composables/useSessionToken.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useCookie } from '#imports'

export default function useSessionToken() {
return useCookie('session_token', {
default: () => '',
Expand Down
1 change: 1 addition & 0 deletions i18n.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TODO: This should be uncommented after 8.0.0-beta.11
import { defineI18nConfig } from '#imports'
import { localeMessages, supportedLocales } from './configUtils'

export default defineI18nConfig(() => ({
Expand Down
4 changes: 4 additions & 0 deletions middleware/confirm-account.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { defineNuxtRouteMiddleware, useRoute, navigateTo } from '#app'
import { useModalAlert } from '#imports'
import { useConfirmAccount } from '~/composables/api'

export default defineNuxtRouteMiddleware((_to, from) => {
const route = useRoute()
const confirmationCode = route.query?.code as string
Expand Down
Loading

0 comments on commit 090b2cf

Please sign in to comment.