Skip to content

Commit

Permalink
Birthday reminders for Persons on your list (se701team3#339)
Browse files Browse the repository at this point in the history
* Created upcoming birthday summary and added card to main page

* Updated date format and birthday api retrieval based on api spec

* Finished adding component to home page properly utilising new api, creating new service functions

* Wrote some static tests where possible (Dates are always changing for birthday so cannot test in same way as previous tests

* Cleaned up code as per review changes, removed duplicate function, and fixed indentation

* Removed service account json

* Fixed test to ignore date
  • Loading branch information
asok3781 authored and abis555 committed Apr 2, 2022
1 parent 98eb047 commit 945f93b
Show file tree
Hide file tree
Showing 52 changed files with 655 additions and 28,733 deletions.
10,228 changes: 32 additions & 10,196 deletions backend/package-lock.json

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const createUser = async (
// Don't return auth_id in the response
res.status(httpStatus.CREATED).json({
_id: createdUser._id,
first_name: createdUser.first_name,
last_name: createdUser.last_name,
name: createdUser.name,
persons: createdUser.persons,
encounters: createdUser.encounters,
companies: createdUser.companies
Expand Down Expand Up @@ -54,8 +53,7 @@ export const getUser = async (
// Don't return auth_id in the response
res.status(httpStatus.OK).json({
_id: user._id,
first_name: user.first_name,
last_name: user.last_name,
name: user.name,
persons: user.persons,
encounters: user.encounters,
companies: user.companies
Expand Down
3 changes: 1 addition & 2 deletions backend/src/controllers/utils/controller-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ export default async function getPersonDetails(personId: any) {
let person = await personService.getPersonWithId(personId);
return {
_id: person?._id,
first_name: person?.first_name,
last_name: person?.last_name,
name: person?.name,
image: person?.image,
};
}
6 changes: 2 additions & 4 deletions backend/src/models/person.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import mongoose, { Schema, model } from 'mongoose';
import { Importance } from '../enums/importance';

export interface PersonModel {
first_name: string,
last_name: string,
name: string,
birthday: Date,
gender: string,
location: string,
Expand All @@ -23,8 +22,7 @@ export interface PersonModel {
}

const schema = new Schema<PersonModel>({
first_name: { type: String, required: true },
last_name: { type: String, required: false },
name: { type: String, required: true },
birthday: { type: Date, required: false },
gender: { type: String, required: false },
location: { type: String, required: false },
Expand Down
6 changes: 2 additions & 4 deletions backend/src/models/user.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import mongoose, { Schema, model } from 'mongoose';

export interface UserModel {
auth_id: string,
first_name: string,
last_name: string,
name: string,
persons: mongoose.Types.ObjectId[]
encounters: mongoose.Types.ObjectId[]
goals: mongoose.Types.ObjectId[]
Expand All @@ -12,8 +11,7 @@ export interface UserModel {

const schema = new Schema<UserModel>({
auth_id: { type: String, required: true },
first_name: { type: String, required: true },
last_name: { type: String, required: true },
name: { type: String, required: true },
persons: { type: [mongoose.Types.ObjectId] },
encounters: { type: [mongoose.Types.ObjectId] },
goals: { type: [mongoose.Types.ObjectId] },
Expand Down
12 changes: 4 additions & 8 deletions backend/src/routes/__test__/company.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,23 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
companies: [] as any
}

const user2Data: UserModel = {
auth_id: null as any,
first_name: 'Adam',
last_name: 'Weng',
name: 'Adam Weng',
encounters: [] as any,
goals: [] as any,
persons: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
organisation: 'helloc',
time_updated: new Date('2022-01-01'),
Expand All @@ -62,8 +59,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
organisation: 'helloc',
time_updated: new Date('2022-02-23'),
Expand Down
12 changes: 4 additions & 8 deletions backend/src/routes/__test__/encounter.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data: UserModel = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
Expand All @@ -36,17 +35,15 @@ const user1Data: UserModel = {

const user2Data: UserModel = {
auth_id: null as any,
first_name: 'Adam',
last_name: 'Weng',
name: 'Adam Weng',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
organisation: 'helloc',
time_updated: new Date('2022-01-01'),
Expand All @@ -63,8 +60,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
organisation: 'helloc',
time_updated: new Date('2022-02-23'),
Expand Down
46 changes: 18 additions & 28 deletions backend/src/routes/__test__/person.route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,15 @@ afterAll(async () => await databaseOperations.closeDatabase());

const user1Data : UserModel = {
auth_id: null as any,
first_name: 'Bing',
last_name: 'Bong',
name: 'Bing Bong',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}

const person1Data: PersonModel = {
first_name: 'Ping',
last_name: 'Pong',
name: 'Ping Pong',
interests: ['video games', 'hockey'],
organisation: 'helloc',
time_updated: new Date('2022-01-01'),
Expand All @@ -53,8 +51,7 @@ const person1Data: PersonModel = {
};

const person2Data: PersonModel = {
first_name: 'Adam',
last_name: 'Bong',
name: 'Adam Bong',
interests: ['badminton', 'golf'],
organisation: 'helloc',
time_updated: new Date('2022-02-23'),
Expand All @@ -71,8 +68,7 @@ const person2Data: PersonModel = {
}

const person3Data: PersonModel = {
first_name: 'Billy',
last_name: 'John',
name: 'Billy John',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
time_updated: new Date('2022-02-23'),
Expand All @@ -89,8 +85,7 @@ const person3Data: PersonModel = {
}

const person4Data: PersonModel = {
first_name: 'Kelvin',
last_name: 'Kong',
name: 'Kelvin Kong',
interests: ['Studying', 'Winning'],
organisation: 'Winnie',
time_updated: new Date('2022-01-01'),
Expand All @@ -108,15 +103,14 @@ const person4Data: PersonModel = {

const userData: UserModel = {
auth_id: null as any,
first_name: 'Ping',
last_name: 'Pengy',
name: 'Ping Pengy',
encounters: [] as any,
persons: [] as any,
goals: [] as any,
companies: [] as any
}
const person5Data = {
last_name: 'John',
name: 'John',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
time_updated: new Date('2022-02-23'),
Expand All @@ -133,8 +127,7 @@ const person5Data = {
}

const person6Data = {
first_name: 'Billy',
last_name: 'John',
name: 'Billy John',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
how_we_met: 'At the park',
Expand Down Expand Up @@ -169,8 +162,7 @@ const encounter2Data: EncounterModel = {
}

const person7Data = {
first_name: 'Yesterday',
last_name: 'Birthday',
name: 'Yesterday Birthday',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
how_we_met: 'At the park',
Expand All @@ -184,8 +176,7 @@ const person7Data = {
}

const person8Data = {
first_name: 'Tomorrow',
last_name: 'Birthday',
name: 'Tomorrow Birthday',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
how_we_met: 'At the park',
Expand All @@ -199,8 +190,7 @@ const person8Data = {
}

const person9Data = {
first_name: 'NextMonth',
last_name: 'Birthday',
name: 'NextMonth Birthday',
interests: ['surfing', 'cooking'],
organisation: 'an organisation',
how_we_met: 'At the park',
Expand Down Expand Up @@ -270,7 +260,7 @@ describe('POST persons/', () => {
expect(user.persons).toEqual([createdPerson._id]);
});

it ('Cannot be created if a first name is not provided', async ()=> {
it ('Cannot be created if the name is not provided', async ()=> {
// Create a new user
await supertest(app).post('/api/users')
.set('Accept', 'application/json')
Expand Down Expand Up @@ -351,11 +341,11 @@ describe('GET persons/', () => {
});

it ('Correctly filters persons by the "term" query param', async () => {
person1Data.first_name = "Bing"
person1Data.name = "Bing Bong"
const person1ID = (await new Person(person1Data).save()).id;
person2Data.first_name = "Billy"
person2Data.name = "Billy John"
const person2ID = (await new Person(person2Data).save()).id;
person3Data.first_name = "John"
person3Data.name = "John"
const person3ID = (await new Person(person3Data).save()).id;

user1Data.persons = [person1ID, person2ID, person3ID];
Expand All @@ -370,8 +360,8 @@ describe('GET persons/', () => {
.expect(httpStatus.OK)

expect(retrievedPersons).toHaveLength(2);
expect(retrievedPersons[0].first_name).toBe("Bing");
expect(retrievedPersons[1].first_name).toBe("Billy");
expect(retrievedPersons[0].name).toBe("Bing Bong");
expect(retrievedPersons[1].name).toBe("Billy John");
});

it ('Returns all persons if the "term" query param is empty', async () => {
Expand All @@ -394,7 +384,7 @@ describe('GET persons/', () => {
});

it ('Does not return duplicates if all persons match the "term" query', async () => {
person1Data.first_name = "A test name";
person1Data.name = "A test name";
const person1ID = (await new Person(person1Data).save()).id;
const person2ID = (await new Person(person1Data).save()).id;
const person3ID = (await new Person(person1Data).save()).id;
Expand Down
Loading

0 comments on commit 945f93b

Please sign in to comment.