-
Notifications
You must be signed in to change notification settings - Fork 5
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
Feature/onboarding tasks #454
Open
maxwn04
wants to merge
14
commits into
master
Choose a base branch
from
feature/onboarding-tasks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f927794
add migration
maxwn04 94b636a
migration and schema changes
maxwn04 cf1df53
change migration and schema
maxwn04 a7e53eb
last change on migration and fix profile
maxwn04 893feb1
add new routes
maxwn04 dc4b8cf
change error
maxwn04 c4aa01c
lint
maxwn04 0b8fe13
done
maxwn04 ec2a28c
Merge branch 'master' into feature/onboarding-tasks
maxwn04 08070e0
fix table and add activity
maxwn04 cb5c996
Merge branch 'feature/onboarding-tasks' of https://github.com/acmucsd…
maxwn04 94474ae
remove return profile
maxwn04 b9acade
fix
maxwn04 de9ffb4
fix test
maxwn04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; | ||
|
||
const TABLE_NAME = 'Users'; | ||
|
||
export class AddOnboardingTask1727933494169 implements MigrationInterface { | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.addColumns(TABLE_NAME, [ | ||
new TableColumn({ | ||
name: 'onboardingSeen', | ||
type: 'boolean', | ||
isNullable: true, | ||
default: false, | ||
}), | ||
new TableColumn({ | ||
name: 'firstTasksCompleted', | ||
type: 'boolean', | ||
isNullable: true, | ||
default: false, | ||
}), | ||
]); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropColumns(TABLE_NAME, [ | ||
new TableColumn({ | ||
name: 'onboardingSeen', | ||
type: 'boolean', | ||
isNullable: false, | ||
default: false, | ||
}), | ||
new TableColumn({ | ||
name: 'firstTasksCompleted', | ||
type: 'boolean', | ||
default: false, | ||
isNullable: false, | ||
}), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { EventModel } from '../models/EventModel'; | ||
import { DatabaseConnection, UserFactory, PortalState, EventFactory, ResumeFactory } from './data'; | ||
import { ControllerFactory } from './controllers'; | ||
|
||
beforeAll(async () => { | ||
await DatabaseConnection.connect(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await DatabaseConnection.clear(); | ||
}); | ||
|
||
afterAll(async () => { | ||
await DatabaseConnection.clear(); | ||
await DatabaseConnection.close(); | ||
}); | ||
|
||
describe('collect onboarding reward', () => { | ||
test('can collect onboarding reward', async () => { | ||
const conn = await DatabaseConnection.get(); | ||
const member = UserFactory.fake({ | ||
bio: 'this is a bio', | ||
profilePicture: 'https://pfp.com', | ||
}); | ||
const resume = ResumeFactory.fake({ user: member, isResumeVisible: true }); | ||
|
||
const events: EventModel[] = []; | ||
for (let i = 0; i < 5; i += 1) { | ||
events.push(EventFactory.fake({ pointValue: 10 })); | ||
} | ||
|
||
await new PortalState() | ||
.createUsers(member) | ||
.createEvents(events[0], events[1], events[2], events[3], events[4]) | ||
.attendEvents([member], events) | ||
.createResumes(member, resume) | ||
.write(); | ||
|
||
const userController = ControllerFactory.user(conn); | ||
const response = await userController.collectOnboarding(member); | ||
const userProfile = response.user; | ||
|
||
expect(userProfile.firstTasksCompleted).toBe(true); | ||
expect(userProfile.points).toBe(60); | ||
}); | ||
|
||
test('conditions not fulfilled', async () => { | ||
const conn = await DatabaseConnection.get(); | ||
const member = UserFactory.fake(); | ||
|
||
await new PortalState() | ||
.createUsers(member) | ||
.write(); | ||
|
||
const userController = ControllerFactory.user(conn); | ||
|
||
await expect(userController.collectOnboarding(member)) | ||
.rejects.toThrow('Onboarding tasks not completed'); | ||
}); | ||
|
||
test('can collect onboarding reward', async () => { | ||
const conn = await DatabaseConnection.get(); | ||
const member = UserFactory.fake({ | ||
bio: 'this is a bio', | ||
profilePicture: 'https://pfp.com', | ||
firstTasksCompleted: true, | ||
}); | ||
const resume = ResumeFactory.fake({ user: member, isResumeVisible: true }); | ||
|
||
const events: EventModel[] = []; | ||
for (let i = 0; i < 5; i += 1) { | ||
events.push(EventFactory.fake({ pointValue: 10 })); | ||
} | ||
|
||
await new PortalState() | ||
.createUsers(member) | ||
.createEvents(events[0], events[1], events[2], events[3], events[4]) | ||
.attendEvents([member], events) | ||
.createResumes(member, resume) | ||
.write(); | ||
|
||
const userController = ControllerFactory.user(conn); | ||
|
||
await expect(userController.collectOnboarding(member)) | ||
.rejects.toThrow('Onboarding reward already collected!'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prior to returning, we should probably also log this in the activity table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do I just add the points bonus to activities or should I do the update to the user model as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Points bonus should just be fine–can you check if we log to activity any time there's a user object edit? I know we do it for user access updates but if there's more instances of it besides that then we can log the update to the user model