All files / services/api/lastwill createLastWill.ts

88.88% Statements 8/9
100% Branches 8/8
100% Functions 1/1
88.88% Lines 8/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27          15x 4x 4x                   3x 1x 2x 1x   1x        
import axios, { isAxiosError } from 'axios'
import { ApiCreateLastWillResponse } from '../../../types/api'
 
type CreateLastWillResponse = ApiCreateLastWillResponse | 'UNAUTHORIZED' | 'PLANS_LIMIT_EXCEEDED' | 'ERROR'
 
export const createLastWill = async (): Promise<CreateLastWillResponse> => {
	try {
		const response = await axios.post<ApiCreateLastWillResponse>(`${process.env.NEXT_PUBLIC_API_BASE_URL}/lastwill`, {
			testator: {
				name: '',
			},
			common: {},
			progressKeys: [],
		})
 
		return response.data
	} catch (error) {
		if (isAxiosError(error) && error.response?.data.statusCode === 401) {
			return 'UNAUTHORIZED'
		} else if (isAxiosError(error) && error.response?.data.statusCode === 403) {
			return 'PLANS_LIMIT_EXCEEDED'
		} else {
			return 'ERROR'
		}
	}
}