Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin - bedel - asistente: solo se devuelven las actividades futuras #45

Merged
merged 3 commits into from
Feb 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions lib/controllers/actividad_controller.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import Actividad from '../models/actividad';
import Turno from '../models/turno';
import { DateTime } from 'luxon';
import Edificio from '../models/edificio';
import Espacio from '../models/espacio';
import Turno from '../models/turno';
import Usuario from '../models/usuario';
import { cleanDb } from '../../test/db_utils';
import { getAuthorizedRequest } from '../../test/config_token';

describe('Actividad controller', () => {
let request;
let espacios;

beforeAll(async () => {
await cleanDb();
Expand All @@ -22,7 +23,7 @@ describe('Actividad controller', () => {
}
);

const espacios = await Espacio.bulkCreate(
espacios = await Espacio.bulkCreate(
[
{
edificioId: edificios[0].id,
Expand Down Expand Up @@ -155,11 +156,42 @@ describe('Actividad controller', () => {
});

describe('/actividades', () => {
beforeAll(() => {
jest.useFakeTimers('modern');

// En JS, Enero es el mes 0, Febrero el mes 1, etc... 🙄
jest.setSystemTime(new Date(2021, 1, 8));
});

afterAll(() => {
jest.useRealTimers();
});

it('devuelve código 200', async () => {
const response = await request.get('/api/actividades');
expect(response.statusCode).toBe(200);
});

it('por defecto no trae actividades pasadas', async () => {
await Actividad.create({
espacioId: espacios[0].id,
nombre: 'Algo que ya pasó',
fechaHoraInicio: DateTime.fromISO('2021-02-07T09:00:00').toISO(),
fechaHoraFin: DateTime.fromISO('2021-02-07T11:00:00').toISO(),
responsable: 'Mariela Tocino',
telefonoDeContactoResponsable: '11458679',
activa: true,
requiereControl: false,
createdAt: new Date(),
updatedAt: new Date(),
});

const response = await request.get('/api/actividades');
expect(response.body.data).not.toContainEqual(
expect.objectContaining({ nombre: 'Algo que ya pasó' })
);
});

it('sin filtro de fecha', async () => {
const response = await request.get('/api/actividades');
expect(response.body.data).toMatchObject([
Expand Down
15 changes: 12 additions & 3 deletions lib/models/actividad.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { DataTypes, Model } from 'sequelize';
import { getFinDelDia, getInicioDelDia } from '../utils/dateUtils';
import {
getFechaActual,
getFinDelDia,
getInicioDelDia,
} from '../utils/dateUtils';

import Turno from './turno';
import Edificio from './edificio';
import Espacio from './espacio';
import { Op } from 'sequelize';
import { Sequelize } from 'sequelize';
import Turno from './turno';
import { isNil } from 'ramda';

export default class Actividad extends Model {
Expand Down Expand Up @@ -55,7 +59,12 @@ export default class Actividad extends Model {
this.hasMany(models.Turno, { foreignKey: 'actividadId' });
}

static conTurnos({ desde, hasta, idsCarreras, inactivas } = {}) {
static conTurnos({
desde = getFechaActual(),
hasta,
idsCarreras,
inactivas,
} = {}) {
return this.findAll({
attributes: {
include: [
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/dateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ export const getInicioDelDia = (fecha) => {
export const getFinDelDia = (fecha) => {
return DateTime.fromISO(fecha).endOf('day').toISO();
};

export const getFechaActual = () => {
return DateTime.local().toISODate();
};