Skip to content

Commit

Permalink
fix: unit tests should work in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
dhenkel92 committed Jan 20, 2024
1 parent 3f506bb commit 0eceb92
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Master Barrier

on:
pull_request:
branches: [master]
types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
integration:
Expand Down
67 changes: 32 additions & 35 deletions common/achievement/bucket.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { BucketCreatorContext, ContextMatch, ContextSubcourse, TimeBucket } from

describe('test create buckets by_lecture_start', () => {
moment.updateLocale('de', { week: { dow: 1 } });
moment.tz.setDefault('Europe/Berlin');
jest.useFakeTimers().setSystemTime(new Date(2023, 7, 15));

const today = moment();
Expand All @@ -23,8 +22,8 @@ describe('test create buckets by_lecture_start', () => {
expectedBuckets: [
{
kind: 'time',
startTime: moment('2023-08-14T21:50:00.000Z').toDate(),
endTime: moment('2023-08-14T23:10:00.000Z').toDate(),
startTime: moment('2023-08-14T23:50:00.000Z').toDate(),
endTime: moment('2023-08-15T01:10:00.000Z').toDate(),
relation: 'match',
},
],
Expand All @@ -35,14 +34,14 @@ describe('test create buckets by_lecture_start', () => {
expectedBuckets: [
{
kind: 'time',
startTime: moment('2023-08-13T21:50:00.000Z').toDate(),
endTime: moment('2023-08-13T23:10:00.000Z').toDate(),
startTime: moment('2023-08-13T23:50:00.000Z').toDate(),
endTime: moment('2023-08-14T01:10:00.000Z').toDate(),
relation: 'match',
},
{
kind: 'time',
startTime: moment('2023-08-14T21:50:00.000Z').toDate(),
endTime: moment('2023-08-14T23:10:00.000Z').toDate(),
startTime: moment('2023-08-14T23:50:00.000Z').toDate(),
endTime: moment('2023-08-15T01:10:00.000Z').toDate(),
relation: 'match',
},
],
Expand All @@ -62,8 +61,8 @@ describe('test create buckets by_lecture_start', () => {
expectedBuckets: [
{
kind: 'time',
startTime: moment('2023-08-14T21:50:00.000Z').toDate(),
endTime: moment('2023-08-14T23:10:00.000Z').toDate(),
startTime: moment('2023-08-14T23:50:00.000Z').toDate(),
endTime: moment('2023-08-15T01:10:00.000Z').toDate(),
relation: 'subcourse',
},
],
Expand All @@ -74,14 +73,14 @@ describe('test create buckets by_lecture_start', () => {
expectedBuckets: [
{
kind: 'time',
startTime: moment('2023-08-13T21:50:00.000Z').toDate(),
endTime: moment('2023-08-13T23:10:00.000Z').toDate(),
startTime: moment('2023-08-13T23:50:00.000Z').toDate(),
endTime: moment('2023-08-14T01:10:00.000Z').toDate(),
relation: 'subcourse',
},
{
kind: 'time',
startTime: moment('2023-08-14T21:50:00.000Z').toDate(),
endTime: moment('2023-08-14T23:10:00.000Z').toDate(),
startTime: moment('2023-08-14T23:50:00.000Z').toDate(),
endTime: moment('2023-08-15T01:10:00.000Z').toDate(),
relation: 'subcourse',
},
],
Expand All @@ -101,26 +100,26 @@ describe('test create buckets by_lecture_start', () => {
expectedBuckets: [
{
kind: 'time',
startTime: moment('2023-08-14T21:50:00.000Z').toDate(),
endTime: moment('2023-08-14T22:40:00.000Z').toDate(),
startTime: moment('2023-08-14T23:50:00.000Z').toDate(),
endTime: moment('2023-08-15T00:40:00.000Z').toDate(),
relation: 'match',
},
{
kind: 'time',
startTime: moment('2023-07-31T21:50:00.000Z').toDate(),
endTime: moment('2023-07-31T22:55:00.000Z').toDate(),
startTime: moment('2023-07-31T23:50:00.000Z').toDate(),
endTime: moment('2023-08-01T00:55:00.000Z').toDate(),
relation: 'match',
},
{
kind: 'time',
startTime: moment('2023-08-13T21:50:00.000Z').toDate(),
endTime: moment('2023-08-13T23:55:00.000Z').toDate(),
startTime: moment('2023-08-13T23:50:00.000Z').toDate(),
endTime: moment('2023-08-14T01:55:00.000Z').toDate(),
relation: 'subcourse',
},
{
kind: 'time',
startTime: moment('2023-08-07T21:50:00.000Z').toDate(),
endTime: moment('2023-08-08T03:00:00.000Z').toDate(),
startTime: moment('2023-08-07T23:50:00.000Z').toDate(),
endTime: moment('2023-08-08T05:00:00.000Z').toDate(),
relation: 'subcourse',
},
],
Expand Down Expand Up @@ -169,7 +168,6 @@ describe('test create buckets by_week', () => {
const today = new Date(2023, 7, 15);

moment.updateLocale('de', { week: { dow: 1 } });
moment.tz.setDefault('Europe/Berlin');
jest.useFakeTimers().setSystemTime(today);

const tests: {
Expand All @@ -181,24 +179,24 @@ describe('test create buckets by_week', () => {
name: 'should create one bucket if recordValue is 0',
recordValue: 0,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-08-13T22:00:00.000Z').toDate(), endTime: moment('2023-08-20T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-14T00:00:00.000Z').toDate(), endTime: moment('2023-08-20T23:59:59.999').toDate(), relation: null },
],
},
{
name: 'should create two buckets if recordValue is 1. Elements should be ordered desc',
recordValue: 1,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-08-13T22:00:00.000Z').toDate(), endTime: moment('2023-08-20T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-06T22:00:00.000Z').toDate(), endTime: moment('2023-08-13T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-14T00:00:00.000Z').toDate(), endTime: moment('2023-08-20T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-07T00:00:00.000Z').toDate(), endTime: moment('2023-08-13T23:59:59.999Z').toDate(), relation: null },
],
},
{
name: 'should create three buckets if recordValue is 2. Elements should be ordered desc',
recordValue: 2,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-08-13T22:00:00.000Z').toDate(), endTime: moment('2023-08-20T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-06T22:00:00.000Z').toDate(), endTime: moment('2023-08-13T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-07-30T22:00:00.000Z').toDate(), endTime: moment('2023-08-06T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-14T00:00:00.000Z').toDate(), endTime: moment('2023-08-20T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-07T00:00:00.000Z').toDate(), endTime: moment('2023-08-13T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-07-31T00:00:00.000Z').toDate(), endTime: moment('2023-08-06T23:59:59.999Z').toDate(), relation: null },
],
},
];
Expand Down Expand Up @@ -226,7 +224,6 @@ describe('test create buckets by_months', () => {
const today = new Date(2023, 7, 15);

moment.updateLocale('de', { week: { dow: 1 } });
moment.tz.setDefault('Europe/Berlin');
jest.useFakeTimers().setSystemTime(today);

const tests: {
Expand All @@ -238,24 +235,24 @@ describe('test create buckets by_months', () => {
name: 'should create one bucket if recordValue is 0',
recordValue: 0,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-07-31T22:00:00.000Z').toDate(), endTime: moment('2023-08-31T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-01T00:00:00.000Z').toDate(), endTime: moment('2023-08-31T23:59:59.999Z').toDate(), relation: null },
],
},
{
name: 'should create two buckets if recordValue is 1. Elements should be ordered desc',
recordValue: 1,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-07-31T22:00:00.000Z').toDate(), endTime: moment('2023-08-31T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-06-30T22:00:00.000Z').toDate(), endTime: moment('2023-07-31T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-01T00:00:00.000Z').toDate(), endTime: moment('2023-08-31T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-07-01T00:00:00.000').toDate(), endTime: moment('2023-07-31T23:59:59.999Z').toDate(), relation: null },
],
},
{
name: 'should create three buckets if recordValue is 2. Elements should be ordered desc',
recordValue: 2,
expectedBuckets: [
{ kind: 'time', startTime: moment('2023-07-31T22:00:00.000Z').toDate(), endTime: moment('2023-08-31T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-06-30T22:00:00.000Z').toDate(), endTime: moment('2023-07-31T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-05-31T22:00:00.000Z').toDate(), endTime: moment('2023-06-30T21:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-08-01T00:00:00.000Z').toDate(), endTime: moment('2023-08-31T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-07-01T00:00:00.000Z').toDate(), endTime: moment('2023-07-31T23:59:59.999Z').toDate(), relation: null },
{ kind: 'time', startTime: moment('2023-06-01T00:00:00.000Z').toDate(), endTime: moment('2023-06-30T23:59:59.999Z').toDate(), relation: null },
],
},
];
Expand Down
2 changes: 0 additions & 2 deletions common/achievement/evaluate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe('evaluate condition without default bucket aggregator', () => {

describe('evaluate record value condition with time buckets', () => {
moment.updateLocale('de', { week: { dow: 1 } });
moment.tz.setDefault('Europe/Berlin');
jest.useFakeTimers().setSystemTime(new Date(2023, 7, 15));

const today = moment();
Expand Down Expand Up @@ -301,7 +300,6 @@ function createLecture({ start }: { start: Date }): lecture {

describe('evaluate bucket with match / subcourse context', () => {
moment.updateLocale('de', { week: { dow: 1 } });
moment.tz.setDefault('Europe/Berlin');
jest.useFakeTimers().setSystemTime(new Date(2023, 7, 15));

const today = moment();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"heroku:release": "./release.sh",
"integration-tests": "node -r source-map-support/register -r dotenv/config ./built/integration-tests/index.js dotenv_config_path=.env.integration-tests",
"integration-tests:debug": "node -r source-map-support/register -r dotenv/config ./built/integration-tests/index.js dotenv_config_path=.env.integration-tests.debug",
"test": "jest",
"test": "TZ=UTC jest",
"db:reset": "prisma migrate reset --skip-generate",
"db:reset-hard": "prisma migrate reset -f --skip-generate",
"db:seed": "node -r dotenv/config ./built/seed-db.js",
Expand Down

0 comments on commit 0eceb92

Please sign in to comment.