TransactionEntity
This commit is contained in:
@@ -100,7 +100,7 @@ describe('Service Tests', () => {
|
||||
});
|
||||
|
||||
it('should partial update a Charge', async () => {
|
||||
const patchObject = { chargeDate: dayjs(currentDate).format(DATE_FORMAT), type: 'BBBBBB', ...new Charge() };
|
||||
const patchObject = { amount: 1, ...new Charge() };
|
||||
const returnedFromService = Object.assign(patchObject, elemDefault);
|
||||
|
||||
const expected = { chargeDate: currentDate, ...returnedFromService };
|
||||
|
||||
@@ -12,6 +12,10 @@
|
||||
<font-awesome-icon icon="asterisk" />
|
||||
<span>Registration</span>
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item to="/transaction">
|
||||
<font-awesome-icon icon="asterisk" />
|
||||
<span>Transaction</span>
|
||||
</b-dropdown-item>
|
||||
<!-- jhipster-needle-add-entity-to-menu - JHipster will add entities to the menu here -->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { defineComponent, provide } from 'vue';
|
||||
import ChargeService from './charge/charge.service';
|
||||
import EventService from './event/event.service';
|
||||
import RegistrationService from './registration/registration.service';
|
||||
import TransactionService from './transaction/transaction.service';
|
||||
import UserService from '@/entities/user/user.service';
|
||||
// jhipster-needle-add-entity-service-to-entities-component-import - JHipster will import entities services here
|
||||
|
||||
@@ -14,6 +15,7 @@ export default defineComponent({
|
||||
provide('chargeService', () => new ChargeService());
|
||||
provide('eventService', () => new EventService());
|
||||
provide('registrationService', () => new RegistrationService());
|
||||
provide('transactionService', () => new TransactionService());
|
||||
// jhipster-needle-add-entity-service-to-entities-component - JHipster will import entities services here
|
||||
},
|
||||
});
|
||||
|
||||
@@ -107,7 +107,7 @@ describe('Service Tests', () => {
|
||||
});
|
||||
|
||||
it('should partial update a Event', async () => {
|
||||
const patchObject = { name: 'BBBBBB', date: dayjs(currentDate).format(DATE_FORMAT), cost: 1, ...new Event() };
|
||||
const patchObject = { cost: 1, ...new Event() };
|
||||
const returnedFromService = Object.assign(patchObject, elemDefault);
|
||||
|
||||
const expected = { date: currentDate, ...returnedFromService };
|
||||
|
||||
@@ -106,7 +106,7 @@ describe('Service Tests', () => {
|
||||
});
|
||||
|
||||
it('should partial update a Registration', async () => {
|
||||
const patchObject = { comment: 'BBBBBB', ...new Registration() };
|
||||
const patchObject = { playerName: 'BBBBBB', comment: 'BBBBBB', ...new Registration() };
|
||||
const returnedFromService = Object.assign(patchObject, elemDefault);
|
||||
|
||||
const expected = { dateTime: currentDate, ...returnedFromService };
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/* tslint:disable max-line-length */
|
||||
import { vitest } from 'vitest';
|
||||
import { type MountingOptions, shallowMount } from '@vue/test-utils';
|
||||
import sinon, { type SinonStubbedInstance } from 'sinon';
|
||||
import { type RouteLocation } from 'vue-router';
|
||||
|
||||
import TransactionDetails from './transaction-details.vue';
|
||||
import TransactionService from './transaction.service';
|
||||
import AlertService from '@/shared/alert/alert.service';
|
||||
|
||||
type TransactionDetailsComponentType = InstanceType<typeof TransactionDetails>;
|
||||
|
||||
let route: Partial<RouteLocation>;
|
||||
const routerGoMock = vitest.fn();
|
||||
|
||||
vitest.mock('vue-router', () => ({
|
||||
useRoute: () => route,
|
||||
useRouter: () => ({ go: routerGoMock }),
|
||||
}));
|
||||
|
||||
const transactionSample = { id: 123 };
|
||||
|
||||
describe('Component Tests', () => {
|
||||
let alertService: AlertService;
|
||||
|
||||
afterEach(() => {
|
||||
vitest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('Transaction Management Detail Component', () => {
|
||||
let transactionServiceStub: SinonStubbedInstance<TransactionService>;
|
||||
let mountOptions: MountingOptions<TransactionDetailsComponentType>['global'];
|
||||
|
||||
beforeEach(() => {
|
||||
route = {};
|
||||
transactionServiceStub = sinon.createStubInstance<TransactionService>(TransactionService);
|
||||
|
||||
alertService = new AlertService({
|
||||
bvToast: {
|
||||
toast: vitest.fn(),
|
||||
} as any,
|
||||
});
|
||||
|
||||
mountOptions = {
|
||||
stubs: {
|
||||
'font-awesome-icon': true,
|
||||
'router-link': true,
|
||||
},
|
||||
provide: {
|
||||
alertService,
|
||||
transactionService: () => transactionServiceStub,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('Navigate to details', () => {
|
||||
it('Should call load all on init', async () => {
|
||||
// GIVEN
|
||||
transactionServiceStub.find.resolves(transactionSample);
|
||||
route = {
|
||||
params: {
|
||||
transactionId: `${123}`,
|
||||
},
|
||||
};
|
||||
const wrapper = shallowMount(TransactionDetails, { global: mountOptions });
|
||||
const comp = wrapper.vm;
|
||||
// WHEN
|
||||
await comp.$nextTick();
|
||||
|
||||
// THEN
|
||||
expect(comp.transaction).toMatchObject(transactionSample);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Previous state', () => {
|
||||
it('Should go previous state', async () => {
|
||||
transactionServiceStub.find.resolves(transactionSample);
|
||||
const wrapper = shallowMount(TransactionDetails, { global: mountOptions });
|
||||
const comp = wrapper.vm;
|
||||
await comp.$nextTick();
|
||||
|
||||
comp.previousState();
|
||||
await comp.$nextTick();
|
||||
|
||||
expect(routerGoMock).toHaveBeenCalledWith(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,41 @@
|
||||
import { type Ref, defineComponent, inject, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
|
||||
import TransactionService from './transaction.service';
|
||||
import { type ITransaction } from '@/shared/model/transaction.model';
|
||||
import { useAlertService } from '@/shared/alert/alert.service';
|
||||
|
||||
export default defineComponent({
|
||||
compatConfig: { MODE: 3 },
|
||||
name: 'TransactionDetails',
|
||||
setup() {
|
||||
const transactionService = inject('transactionService', () => new TransactionService());
|
||||
const alertService = inject('alertService', () => useAlertService(), true);
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const previousState = () => router.go(-1);
|
||||
const transaction: Ref<ITransaction> = ref({});
|
||||
|
||||
const retrieveTransaction = async transactionId => {
|
||||
try {
|
||||
const res = await transactionService().find(transactionId);
|
||||
transaction.value = res;
|
||||
} catch (error) {
|
||||
alertService.showHttpError(error.response);
|
||||
}
|
||||
};
|
||||
|
||||
if (route.params?.transactionId) {
|
||||
retrieveTransaction(route.params.transactionId);
|
||||
}
|
||||
|
||||
return {
|
||||
alertService,
|
||||
transaction,
|
||||
|
||||
previousState,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
<template>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<div v-if="transaction">
|
||||
<h2 class="jh-entity-heading" data-cy="transactionDetailsHeading"><span>Transaction</span> {{ transaction.id }}</h2>
|
||||
<dl class="row jh-entity-details">
|
||||
<dt>
|
||||
<span>Type</span>
|
||||
</dt>
|
||||
<dd>
|
||||
<span>{{ transaction.type }}</span>
|
||||
</dd>
|
||||
<dt>
|
||||
<span>Date</span>
|
||||
</dt>
|
||||
<dd>
|
||||
<span>{{ transaction.date }}</span>
|
||||
</dd>
|
||||
<dt>
|
||||
<span>Comment</span>
|
||||
</dt>
|
||||
<dd>
|
||||
<span>{{ transaction.comment }}</span>
|
||||
</dd>
|
||||
<dt>
|
||||
<span>Event</span>
|
||||
</dt>
|
||||
<dd>
|
||||
<div v-if="transaction.event">
|
||||
<router-link :to="{ name: 'EventView', params: { eventId: transaction.event.id } }">{{ transaction.event.name }}</router-link>
|
||||
</div>
|
||||
</dd>
|
||||
</dl>
|
||||
<button type="submit" @click.prevent="previousState()" class="btn btn-info" data-cy="entityDetailsBackButton">
|
||||
<font-awesome-icon icon="arrow-left"></font-awesome-icon> <span>Back</span>
|
||||
</button>
|
||||
<router-link
|
||||
v-if="transaction.id"
|
||||
:to="{ name: 'TransactionEdit', params: { transactionId: transaction.id } }"
|
||||
custom
|
||||
v-slot="{ navigate }"
|
||||
>
|
||||
<button @click="navigate" class="btn btn-primary">
|
||||
<font-awesome-icon icon="pencil-alt"></font-awesome-icon> <span>Edit</span>
|
||||
</button>
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" src="./transaction-details.component.ts"></script>
|
||||
@@ -0,0 +1,137 @@
|
||||
/* tslint:disable max-line-length */
|
||||
import { vitest } from 'vitest';
|
||||
import { type MountingOptions, shallowMount } from '@vue/test-utils';
|
||||
import sinon, { type SinonStubbedInstance } from 'sinon';
|
||||
import { type RouteLocation } from 'vue-router';
|
||||
|
||||
import TransactionUpdate from './transaction-update.vue';
|
||||
import TransactionService from './transaction.service';
|
||||
import AlertService from '@/shared/alert/alert.service';
|
||||
|
||||
import EventService from '@/entities/event/event.service';
|
||||
|
||||
type TransactionUpdateComponentType = InstanceType<typeof TransactionUpdate>;
|
||||
|
||||
let route: Partial<RouteLocation>;
|
||||
const routerGoMock = vitest.fn();
|
||||
|
||||
vitest.mock('vue-router', () => ({
|
||||
useRoute: () => route,
|
||||
useRouter: () => ({ go: routerGoMock }),
|
||||
}));
|
||||
|
||||
const transactionSample = { id: 123 };
|
||||
|
||||
describe('Component Tests', () => {
|
||||
let mountOptions: MountingOptions<TransactionUpdateComponentType>['global'];
|
||||
let alertService: AlertService;
|
||||
|
||||
describe('Transaction Management Update Component', () => {
|
||||
let comp: TransactionUpdateComponentType;
|
||||
let transactionServiceStub: SinonStubbedInstance<TransactionService>;
|
||||
|
||||
beforeEach(() => {
|
||||
route = {};
|
||||
transactionServiceStub = sinon.createStubInstance<TransactionService>(TransactionService);
|
||||
transactionServiceStub.retrieve.onFirstCall().resolves(Promise.resolve([]));
|
||||
|
||||
alertService = new AlertService({
|
||||
bvToast: {
|
||||
toast: vitest.fn(),
|
||||
} as any,
|
||||
});
|
||||
|
||||
mountOptions = {
|
||||
stubs: {
|
||||
'font-awesome-icon': true,
|
||||
'b-input-group': true,
|
||||
'b-input-group-prepend': true,
|
||||
'b-form-datepicker': true,
|
||||
'b-form-input': true,
|
||||
},
|
||||
provide: {
|
||||
alertService,
|
||||
transactionService: () => transactionServiceStub,
|
||||
eventService: () =>
|
||||
sinon.createStubInstance<EventService>(EventService, {
|
||||
retrieve: sinon.stub().resolves({}),
|
||||
} as any),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vitest.resetAllMocks();
|
||||
});
|
||||
|
||||
describe('save', () => {
|
||||
it('Should call update service on save for existing entity', async () => {
|
||||
// GIVEN
|
||||
const wrapper = shallowMount(TransactionUpdate, { global: mountOptions });
|
||||
comp = wrapper.vm;
|
||||
comp.transaction = transactionSample;
|
||||
transactionServiceStub.update.resolves(transactionSample);
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
await comp.$nextTick();
|
||||
|
||||
// THEN
|
||||
expect(transactionServiceStub.update.calledWith(transactionSample)).toBeTruthy();
|
||||
expect(comp.isSaving).toEqual(false);
|
||||
});
|
||||
|
||||
it('Should call create service on save for new entity', async () => {
|
||||
// GIVEN
|
||||
const entity = {};
|
||||
transactionServiceStub.create.resolves(entity);
|
||||
const wrapper = shallowMount(TransactionUpdate, { global: mountOptions });
|
||||
comp = wrapper.vm;
|
||||
comp.transaction = entity;
|
||||
|
||||
// WHEN
|
||||
comp.save();
|
||||
await comp.$nextTick();
|
||||
|
||||
// THEN
|
||||
expect(transactionServiceStub.create.calledWith(entity)).toBeTruthy();
|
||||
expect(comp.isSaving).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Before route enter', () => {
|
||||
it('Should retrieve data', async () => {
|
||||
// GIVEN
|
||||
transactionServiceStub.find.resolves(transactionSample);
|
||||
transactionServiceStub.retrieve.resolves([transactionSample]);
|
||||
|
||||
// WHEN
|
||||
route = {
|
||||
params: {
|
||||
transactionId: `${transactionSample.id}`,
|
||||
},
|
||||
};
|
||||
const wrapper = shallowMount(TransactionUpdate, { global: mountOptions });
|
||||
comp = wrapper.vm;
|
||||
await comp.$nextTick();
|
||||
|
||||
// THEN
|
||||
expect(comp.transaction).toMatchObject(transactionSample);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Previous state', () => {
|
||||
it('Should go previous state', async () => {
|
||||
transactionServiceStub.find.resolves(transactionSample);
|
||||
const wrapper = shallowMount(TransactionUpdate, { global: mountOptions });
|
||||
comp = wrapper.vm;
|
||||
await comp.$nextTick();
|
||||
|
||||
comp.previousState();
|
||||
await comp.$nextTick();
|
||||
|
||||
expect(routerGoMock).toHaveBeenCalledWith(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import { type Ref, computed, defineComponent, inject, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useVuelidate } from '@vuelidate/core';
|
||||
|
||||
import TransactionService from './transaction.service';
|
||||
import { useValidation } from '@/shared/composables';
|
||||
import { useAlertService } from '@/shared/alert/alert.service';
|
||||
|
||||
import EventService from '@/entities/event/event.service';
|
||||
import { type IEvent } from '@/shared/model/event.model';
|
||||
import { type ITransaction, Transaction } from '@/shared/model/transaction.model';
|
||||
import { TransactionType } from '@/shared/model/enumerations/transaction-type.model';
|
||||
|
||||
export default defineComponent({
|
||||
compatConfig: { MODE: 3 },
|
||||
name: 'TransactionUpdate',
|
||||
setup() {
|
||||
const transactionService = inject('transactionService', () => new TransactionService());
|
||||
const alertService = inject('alertService', () => useAlertService(), true);
|
||||
|
||||
const transaction: Ref<ITransaction> = ref(new Transaction());
|
||||
|
||||
const eventService = inject('eventService', () => new EventService());
|
||||
|
||||
const events: Ref<IEvent[]> = ref([]);
|
||||
const transactionTypeValues: Ref<string[]> = ref(Object.keys(TransactionType));
|
||||
const isSaving = ref(false);
|
||||
const currentLanguage = inject('currentLanguage', () => computed(() => navigator.language ?? 'en'), true);
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
const previousState = () => router.go(-1);
|
||||
|
||||
const retrieveTransaction = async transactionId => {
|
||||
try {
|
||||
const res = await transactionService().find(transactionId);
|
||||
transaction.value = res;
|
||||
} catch (error) {
|
||||
alertService.showHttpError(error.response);
|
||||
}
|
||||
};
|
||||
|
||||
if (route.params?.transactionId) {
|
||||
retrieveTransaction(route.params.transactionId);
|
||||
}
|
||||
|
||||
const initRelationships = () => {
|
||||
eventService()
|
||||
.retrieve()
|
||||
.then(res => {
|
||||
events.value = res.data;
|
||||
});
|
||||
};
|
||||
|
||||
initRelationships();
|
||||
|
||||
const validations = useValidation();
|
||||
const validationRules = {
|
||||
type: {},
|
||||
date: {},
|
||||
comment: {},
|
||||
event: {},
|
||||
};
|
||||
const v$ = useVuelidate(validationRules, transaction as any);
|
||||
v$.value.$validate();
|
||||
|
||||
return {
|
||||
transactionService,
|
||||
alertService,
|
||||
transaction,
|
||||
previousState,
|
||||
transactionTypeValues,
|
||||
isSaving,
|
||||
currentLanguage,
|
||||
events,
|
||||
v$,
|
||||
};
|
||||
},
|
||||
created(): void {},
|
||||
methods: {
|
||||
save(): void {
|
||||
this.isSaving = true;
|
||||
if (this.transaction.id) {
|
||||
this.transactionService()
|
||||
.update(this.transaction)
|
||||
.then(param => {
|
||||
this.isSaving = false;
|
||||
this.previousState();
|
||||
this.alertService.showInfo(`A Transaction is updated with identifier ${param.id}`);
|
||||
})
|
||||
.catch(error => {
|
||||
this.isSaving = false;
|
||||
this.alertService.showHttpError(error.response);
|
||||
});
|
||||
} else {
|
||||
this.transactionService()
|
||||
.create(this.transaction)
|
||||
.then(param => {
|
||||
this.isSaving = false;
|
||||
this.previousState();
|
||||
this.alertService.showSuccess(`A Transaction is created with identifier ${param.id}`);
|
||||
})
|
||||
.catch(error => {
|
||||
this.isSaving = false;
|
||||
this.alertService.showHttpError(error.response);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,98 @@
|
||||
<template>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<form name="editForm" novalidate @submit.prevent="save()">
|
||||
<h2 id="sasiedziApp.transaction.home.createOrEditLabel" data-cy="TransactionCreateUpdateHeading">Create or edit a Transaction</h2>
|
||||
<div>
|
||||
<div class="form-group" v-if="transaction.id">
|
||||
<label for="id">ID</label>
|
||||
<input type="text" class="form-control" id="id" name="id" v-model="transaction.id" readonly />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="transaction-type">Type</label>
|
||||
<select
|
||||
class="form-control"
|
||||
name="type"
|
||||
:class="{ valid: !v$.type.$invalid, invalid: v$.type.$invalid }"
|
||||
v-model="v$.type.$model"
|
||||
id="transaction-type"
|
||||
data-cy="type"
|
||||
>
|
||||
<option v-for="transactionType in transactionTypeValues" :key="transactionType" :value="transactionType">
|
||||
{{ transactionType }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="transaction-date">Date</label>
|
||||
<b-input-group class="mb-3">
|
||||
<b-input-group-prepend>
|
||||
<b-form-datepicker
|
||||
aria-controls="transaction-date"
|
||||
v-model="v$.date.$model"
|
||||
name="date"
|
||||
class="form-control"
|
||||
:locale="currentLanguage"
|
||||
button-only
|
||||
today-button
|
||||
reset-button
|
||||
close-button
|
||||
>
|
||||
</b-form-datepicker>
|
||||
</b-input-group-prepend>
|
||||
<b-form-input
|
||||
id="transaction-date"
|
||||
data-cy="date"
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="date"
|
||||
:class="{ valid: !v$.date.$invalid, invalid: v$.date.$invalid }"
|
||||
v-model="v$.date.$model"
|
||||
/>
|
||||
</b-input-group>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="transaction-comment">Comment</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
name="comment"
|
||||
id="transaction-comment"
|
||||
data-cy="comment"
|
||||
:class="{ valid: !v$.comment.$invalid, invalid: v$.comment.$invalid }"
|
||||
v-model="v$.comment.$model"
|
||||
/>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-control-label" for="transaction-event">Event</label>
|
||||
<select class="form-control" id="transaction-event" data-cy="event" name="event" v-model="transaction.event">
|
||||
<option :value="null"></option>
|
||||
<option
|
||||
:value="transaction.event && eventOption.id === transaction.event.id ? transaction.event : eventOption"
|
||||
v-for="eventOption in events"
|
||||
:key="eventOption.id"
|
||||
>
|
||||
{{ eventOption.name }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" id="cancel-save" data-cy="entityCreateCancelButton" class="btn btn-secondary" @click="previousState()">
|
||||
<font-awesome-icon icon="ban"></font-awesome-icon> <span>Cancel</span>
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
id="save-entity"
|
||||
data-cy="entityCreateSaveButton"
|
||||
:disabled="v$.$invalid || isSaving"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
<font-awesome-icon icon="save"></font-awesome-icon> <span>Save</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" src="./transaction-update.component.ts"></script>
|
||||
@@ -0,0 +1,100 @@
|
||||
/* tslint:disable max-line-length */
|
||||
import { vitest } from 'vitest';
|
||||
import { type MountingOptions, shallowMount } from '@vue/test-utils';
|
||||
import sinon, { type SinonStubbedInstance } from 'sinon';
|
||||
|
||||
import Transaction from './transaction.vue';
|
||||
import TransactionService from './transaction.service';
|
||||
import AlertService from '@/shared/alert/alert.service';
|
||||
|
||||
type TransactionComponentType = InstanceType<typeof Transaction>;
|
||||
|
||||
const bModalStub = {
|
||||
render: () => {},
|
||||
methods: {
|
||||
hide: () => {},
|
||||
show: () => {},
|
||||
},
|
||||
};
|
||||
|
||||
describe('Component Tests', () => {
|
||||
let alertService: AlertService;
|
||||
|
||||
describe('Transaction Management Component', () => {
|
||||
let transactionServiceStub: SinonStubbedInstance<TransactionService>;
|
||||
let mountOptions: MountingOptions<TransactionComponentType>['global'];
|
||||
|
||||
beforeEach(() => {
|
||||
transactionServiceStub = sinon.createStubInstance<TransactionService>(TransactionService);
|
||||
transactionServiceStub.retrieve.resolves({ headers: {} });
|
||||
|
||||
alertService = new AlertService({
|
||||
bvToast: {
|
||||
toast: vitest.fn(),
|
||||
} as any,
|
||||
});
|
||||
|
||||
mountOptions = {
|
||||
stubs: {
|
||||
bModal: bModalStub as any,
|
||||
'font-awesome-icon': true,
|
||||
'b-badge': true,
|
||||
'b-button': true,
|
||||
'router-link': true,
|
||||
},
|
||||
directives: {
|
||||
'b-modal': {},
|
||||
},
|
||||
provide: {
|
||||
alertService,
|
||||
transactionService: () => transactionServiceStub,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('Mount', () => {
|
||||
it('Should call load all on init', async () => {
|
||||
// GIVEN
|
||||
transactionServiceStub.retrieve.resolves({ headers: {}, data: [{ id: 123 }] });
|
||||
|
||||
// WHEN
|
||||
const wrapper = shallowMount(Transaction, { global: mountOptions });
|
||||
const comp = wrapper.vm;
|
||||
await comp.$nextTick();
|
||||
|
||||
// THEN
|
||||
expect(transactionServiceStub.retrieve.calledOnce).toBeTruthy();
|
||||
expect(comp.transactions[0]).toEqual(expect.objectContaining({ id: 123 }));
|
||||
});
|
||||
});
|
||||
describe('Handles', () => {
|
||||
let comp: TransactionComponentType;
|
||||
|
||||
beforeEach(async () => {
|
||||
const wrapper = shallowMount(Transaction, { global: mountOptions });
|
||||
comp = wrapper.vm;
|
||||
await comp.$nextTick();
|
||||
transactionServiceStub.retrieve.reset();
|
||||
transactionServiceStub.retrieve.resolves({ headers: {}, data: [] });
|
||||
});
|
||||
|
||||
it('Should call delete service on confirmDelete', async () => {
|
||||
// GIVEN
|
||||
transactionServiceStub.delete.resolves({});
|
||||
|
||||
// WHEN
|
||||
comp.prepareRemove({ id: 123 });
|
||||
|
||||
comp.removeTransaction();
|
||||
await comp.$nextTick(); // clear components
|
||||
|
||||
// THEN
|
||||
expect(transactionServiceStub.delete.called).toBeTruthy();
|
||||
|
||||
// THEN
|
||||
await comp.$nextTick(); // handle component clear watch
|
||||
expect(transactionServiceStub.retrieve.callCount).toEqual(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { type Ref, defineComponent, inject, onMounted, ref } from 'vue';
|
||||
|
||||
import TransactionService from './transaction.service';
|
||||
import { type ITransaction } from '@/shared/model/transaction.model';
|
||||
import { useAlertService } from '@/shared/alert/alert.service';
|
||||
|
||||
export default defineComponent({
|
||||
compatConfig: { MODE: 3 },
|
||||
name: 'Transaction',
|
||||
setup() {
|
||||
const transactionService = inject('transactionService', () => new TransactionService());
|
||||
const alertService = inject('alertService', () => useAlertService(), true);
|
||||
|
||||
const transactions: Ref<ITransaction[]> = ref([]);
|
||||
|
||||
const isFetching = ref(false);
|
||||
|
||||
const clear = () => {};
|
||||
|
||||
const retrieveTransactions = async () => {
|
||||
isFetching.value = true;
|
||||
try {
|
||||
const res = await transactionService().retrieve();
|
||||
transactions.value = res.data;
|
||||
} catch (err) {
|
||||
alertService.showHttpError(err.response);
|
||||
} finally {
|
||||
isFetching.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleSyncList = () => {
|
||||
retrieveTransactions();
|
||||
};
|
||||
|
||||
onMounted(async () => {
|
||||
await retrieveTransactions();
|
||||
});
|
||||
|
||||
const removeId: Ref<number> = ref(null);
|
||||
const removeEntity = ref<any>(null);
|
||||
const prepareRemove = (instance: ITransaction) => {
|
||||
removeId.value = instance.id;
|
||||
removeEntity.value.show();
|
||||
};
|
||||
const closeDialog = () => {
|
||||
removeEntity.value.hide();
|
||||
};
|
||||
const removeTransaction = async () => {
|
||||
try {
|
||||
await transactionService().delete(removeId.value);
|
||||
const message = `A Transaction is deleted with identifier ${removeId.value}`;
|
||||
alertService.showInfo(message, { variant: 'danger' });
|
||||
removeId.value = null;
|
||||
retrieveTransactions();
|
||||
closeDialog();
|
||||
} catch (error) {
|
||||
alertService.showHttpError(error.response);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
transactions,
|
||||
handleSyncList,
|
||||
isFetching,
|
||||
retrieveTransactions,
|
||||
clear,
|
||||
removeId,
|
||||
removeEntity,
|
||||
prepareRemove,
|
||||
closeDialog,
|
||||
removeTransaction,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
/* tslint:disable max-line-length */
|
||||
import axios from 'axios';
|
||||
import sinon from 'sinon';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import TransactionService from './transaction.service';
|
||||
import { DATE_FORMAT } from '@/shared/composables/date-format';
|
||||
import { Transaction } from '@/shared/model/transaction.model';
|
||||
|
||||
const error = {
|
||||
response: {
|
||||
status: null,
|
||||
data: {
|
||||
type: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const axiosStub = {
|
||||
get: sinon.stub(axios, 'get'),
|
||||
post: sinon.stub(axios, 'post'),
|
||||
put: sinon.stub(axios, 'put'),
|
||||
patch: sinon.stub(axios, 'patch'),
|
||||
delete: sinon.stub(axios, 'delete'),
|
||||
};
|
||||
|
||||
describe('Service Tests', () => {
|
||||
describe('Transaction Service', () => {
|
||||
let service: TransactionService;
|
||||
let elemDefault;
|
||||
let currentDate: Date;
|
||||
|
||||
beforeEach(() => {
|
||||
service = new TransactionService();
|
||||
currentDate = new Date();
|
||||
elemDefault = new Transaction(123, 'PURCHASE', currentDate, 'AAAAAAA');
|
||||
});
|
||||
|
||||
describe('Service methods', () => {
|
||||
it('should find an element', async () => {
|
||||
const returnedFromService = { date: dayjs(currentDate).format(DATE_FORMAT), ...elemDefault };
|
||||
axiosStub.get.resolves({ data: returnedFromService });
|
||||
|
||||
return service.find(123).then(res => {
|
||||
expect(res).toMatchObject(elemDefault);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not find an element', async () => {
|
||||
axiosStub.get.rejects(error);
|
||||
return service
|
||||
.find(123)
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should create a Transaction', async () => {
|
||||
const returnedFromService = { id: 123, date: dayjs(currentDate).format(DATE_FORMAT), ...elemDefault };
|
||||
const expected = { date: currentDate, ...returnedFromService };
|
||||
|
||||
axiosStub.post.resolves({ data: returnedFromService });
|
||||
return service.create({}).then(res => {
|
||||
expect(res).toMatchObject(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not create a Transaction', async () => {
|
||||
axiosStub.post.rejects(error);
|
||||
|
||||
return service
|
||||
.create({})
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update a Transaction', async () => {
|
||||
const returnedFromService = { type: 'BBBBBB', date: dayjs(currentDate).format(DATE_FORMAT), comment: 'BBBBBB', ...elemDefault };
|
||||
|
||||
const expected = { date: currentDate, ...returnedFromService };
|
||||
axiosStub.put.resolves({ data: returnedFromService });
|
||||
|
||||
return service.update(expected).then(res => {
|
||||
expect(res).toMatchObject(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not update a Transaction', async () => {
|
||||
axiosStub.put.rejects(error);
|
||||
|
||||
return service
|
||||
.update({})
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should partial update a Transaction', async () => {
|
||||
const patchObject = { type: 'BBBBBB', date: dayjs(currentDate).format(DATE_FORMAT), ...new Transaction() };
|
||||
const returnedFromService = Object.assign(patchObject, elemDefault);
|
||||
|
||||
const expected = { date: currentDate, ...returnedFromService };
|
||||
axiosStub.patch.resolves({ data: returnedFromService });
|
||||
|
||||
return service.partialUpdate(patchObject).then(res => {
|
||||
expect(res).toMatchObject(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not partial update a Transaction', async () => {
|
||||
axiosStub.patch.rejects(error);
|
||||
|
||||
return service
|
||||
.partialUpdate({})
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a list of Transaction', async () => {
|
||||
const returnedFromService = { type: 'BBBBBB', date: dayjs(currentDate).format(DATE_FORMAT), comment: 'BBBBBB', ...elemDefault };
|
||||
const expected = { date: currentDate, ...returnedFromService };
|
||||
axiosStub.get.resolves([returnedFromService]);
|
||||
return service.retrieve().then(res => {
|
||||
expect(res).toContainEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not return a list of Transaction', async () => {
|
||||
axiosStub.get.rejects(error);
|
||||
|
||||
return service
|
||||
.retrieve()
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
|
||||
it('should delete a Transaction', async () => {
|
||||
axiosStub.delete.resolves({ ok: true });
|
||||
return service.delete(123).then(res => {
|
||||
expect(res.ok).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not delete a Transaction', async () => {
|
||||
axiosStub.delete.rejects(error);
|
||||
|
||||
return service
|
||||
.delete(123)
|
||||
.then()
|
||||
.catch(err => {
|
||||
expect(err).toMatchObject(error);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,85 @@
|
||||
import axios from 'axios';
|
||||
|
||||
import { type ITransaction } from '@/shared/model/transaction.model';
|
||||
|
||||
const baseApiUrl = 'api/transactions';
|
||||
|
||||
export default class TransactionService {
|
||||
public find(id: number): Promise<ITransaction> {
|
||||
return new Promise<ITransaction>((resolve, reject) => {
|
||||
axios
|
||||
.get(`${baseApiUrl}/${id}`)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public retrieve(): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
axios
|
||||
.get(baseApiUrl)
|
||||
.then(res => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public delete(id: number): Promise<any> {
|
||||
return new Promise<any>((resolve, reject) => {
|
||||
axios
|
||||
.delete(`${baseApiUrl}/${id}`)
|
||||
.then(res => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public create(entity: ITransaction): Promise<ITransaction> {
|
||||
return new Promise<ITransaction>((resolve, reject) => {
|
||||
axios
|
||||
.post(`${baseApiUrl}`, entity)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public update(entity: ITransaction): Promise<ITransaction> {
|
||||
return new Promise<ITransaction>((resolve, reject) => {
|
||||
axios
|
||||
.put(`${baseApiUrl}/${entity.id}`, entity)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public partialUpdate(entity: ITransaction): Promise<ITransaction> {
|
||||
return new Promise<ITransaction>((resolve, reject) => {
|
||||
axios
|
||||
.patch(`${baseApiUrl}/${entity.id}`, entity)
|
||||
.then(res => {
|
||||
resolve(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2 id="page-heading" data-cy="TransactionHeading">
|
||||
<span id="transaction-heading">Transactions</span>
|
||||
<div class="d-flex justify-content-end">
|
||||
<button class="btn btn-info mr-2" @click="handleSyncList" :disabled="isFetching">
|
||||
<font-awesome-icon icon="sync" :spin="isFetching"></font-awesome-icon> <span>Refresh list</span>
|
||||
</button>
|
||||
<router-link :to="{ name: 'TransactionCreate' }" custom v-slot="{ navigate }">
|
||||
<button
|
||||
@click="navigate"
|
||||
id="jh-create-entity"
|
||||
data-cy="entityCreateButton"
|
||||
class="btn btn-primary jh-create-entity create-transaction"
|
||||
>
|
||||
<font-awesome-icon icon="plus"></font-awesome-icon>
|
||||
<span>Create a new Transaction</span>
|
||||
</button>
|
||||
</router-link>
|
||||
</div>
|
||||
</h2>
|
||||
<br />
|
||||
<div class="alert alert-warning" v-if="!isFetching && transactions && transactions.length === 0">
|
||||
<span>No Transactions found</span>
|
||||
</div>
|
||||
<div class="table-responsive" v-if="transactions && transactions.length > 0">
|
||||
<table class="table table-striped" aria-describedby="transactions">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="row"><span>ID</span></th>
|
||||
<th scope="row"><span>Type</span></th>
|
||||
<th scope="row"><span>Date</span></th>
|
||||
<th scope="row"><span>Comment</span></th>
|
||||
<th scope="row"><span>Event</span></th>
|
||||
<th scope="row"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="transaction in transactions" :key="transaction.id" data-cy="entityTable">
|
||||
<td>
|
||||
<router-link :to="{ name: 'TransactionView', params: { transactionId: transaction.id } }">{{ transaction.id }}</router-link>
|
||||
</td>
|
||||
<td>{{ transaction.type }}</td>
|
||||
<td>{{ transaction.date }}</td>
|
||||
<td>{{ transaction.comment }}</td>
|
||||
<td>
|
||||
<div v-if="transaction.event">
|
||||
<router-link :to="{ name: 'EventView', params: { eventId: transaction.event.id } }">{{
|
||||
transaction.event.name
|
||||
}}</router-link>
|
||||
</div>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<div class="btn-group">
|
||||
<router-link :to="{ name: 'TransactionView', params: { transactionId: transaction.id } }" custom v-slot="{ navigate }">
|
||||
<button @click="navigate" class="btn btn-info btn-sm details" data-cy="entityDetailsButton">
|
||||
<font-awesome-icon icon="eye"></font-awesome-icon>
|
||||
<span class="d-none d-md-inline">View</span>
|
||||
</button>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'TransactionEdit', params: { transactionId: transaction.id } }" custom v-slot="{ navigate }">
|
||||
<button @click="navigate" class="btn btn-primary btn-sm edit" data-cy="entityEditButton">
|
||||
<font-awesome-icon icon="pencil-alt"></font-awesome-icon>
|
||||
<span class="d-none d-md-inline">Edit</span>
|
||||
</button>
|
||||
</router-link>
|
||||
<b-button
|
||||
@click="prepareRemove(transaction)"
|
||||
variant="danger"
|
||||
class="btn btn-sm"
|
||||
data-cy="entityDeleteButton"
|
||||
v-b-modal.removeEntity
|
||||
>
|
||||
<font-awesome-icon icon="times"></font-awesome-icon>
|
||||
<span class="d-none d-md-inline">Delete</span>
|
||||
</b-button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<b-modal ref="removeEntity" id="removeEntity">
|
||||
<template #modal-title>
|
||||
<span id="sasiedziApp.transaction.delete.question" data-cy="transactionDeleteDialogHeading">Confirm delete operation</span>
|
||||
</template>
|
||||
<div class="modal-body">
|
||||
<p id="jhi-delete-transaction-heading">Are you sure you want to delete Transaction {{ removeId }}?</p>
|
||||
</div>
|
||||
<template #modal-footer>
|
||||
<div>
|
||||
<button type="button" class="btn btn-secondary" @click="closeDialog()">Cancel</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
id="jhi-confirm-delete-transaction"
|
||||
data-cy="entityConfirmDeleteButton"
|
||||
@click="removeTransaction()"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</b-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" src="./transaction.component.ts"></script>
|
||||
@@ -15,6 +15,10 @@ const Registration = () => import('@/entities/registration/registration.vue');
|
||||
const RegistrationUpdate = () => import('@/entities/registration/registration-update.vue');
|
||||
const RegistrationDetails = () => import('@/entities/registration/registration-details.vue');
|
||||
|
||||
const Transaction = () => import('@/entities/transaction/transaction.vue');
|
||||
const TransactionUpdate = () => import('@/entities/transaction/transaction-update.vue');
|
||||
const TransactionDetails = () => import('@/entities/transaction/transaction-details.vue');
|
||||
|
||||
// jhipster-needle-add-entity-to-router-import - JHipster will import entities to the router here
|
||||
|
||||
export default {
|
||||
@@ -93,6 +97,30 @@ export default {
|
||||
component: RegistrationDetails,
|
||||
meta: { authorities: [Authority.USER] },
|
||||
},
|
||||
{
|
||||
path: 'transaction',
|
||||
name: 'Transaction',
|
||||
component: Transaction,
|
||||
meta: { authorities: [Authority.USER] },
|
||||
},
|
||||
{
|
||||
path: 'transaction/new',
|
||||
name: 'TransactionCreate',
|
||||
component: TransactionUpdate,
|
||||
meta: { authorities: [Authority.USER] },
|
||||
},
|
||||
{
|
||||
path: 'transaction/:transactionId/edit',
|
||||
name: 'TransactionEdit',
|
||||
component: TransactionUpdate,
|
||||
meta: { authorities: [Authority.USER] },
|
||||
},
|
||||
{
|
||||
path: 'transaction/:transactionId/view',
|
||||
name: 'TransactionView',
|
||||
component: TransactionDetails,
|
||||
meta: { authorities: [Authority.USER] },
|
||||
},
|
||||
// jhipster-needle-add-entity-to-router - JHipster will add entities to the router here
|
||||
],
|
||||
};
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
export enum TransactionType {
|
||||
PURCHASE = 'PURCHASE',
|
||||
|
||||
MATCH = 'MATCH',
|
||||
|
||||
FIELDPAYMENT = 'FIELDPAYMENT',
|
||||
|
||||
INTERNALTRANSFER = 'INTERNALTRANSFER',
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { type IEvent } from '@/shared/model/event.model';
|
||||
|
||||
import { type TransactionType } from '@/shared/model/enumerations/transaction-type.model';
|
||||
export interface ITransaction {
|
||||
id?: number;
|
||||
type?: keyof typeof TransactionType | null;
|
||||
date?: Date | null;
|
||||
comment?: string | null;
|
||||
event?: IEvent | null;
|
||||
}
|
||||
|
||||
export class Transaction implements ITransaction {
|
||||
constructor(
|
||||
public id?: number,
|
||||
public type?: keyof typeof TransactionType | null,
|
||||
public date?: Date | null,
|
||||
public comment?: string | null,
|
||||
public event?: IEvent | null,
|
||||
) {}
|
||||
}
|
||||
Reference in New Issue
Block a user