-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): create share profile route and controller
- Loading branch information
1 parent
9aaa251
commit d2bad35
Showing
5 changed files
with
178 additions
and
15 deletions.
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
76 changes: 76 additions & 0 deletions
76
api/tests/profile/acceptance/application/share-profile-reward-route_test.js
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,76 @@ | ||
import { | ||
createServer, | ||
databaseBuilder, | ||
expect, | ||
generateValidRequestAuthorizationHeader, | ||
} from '../../../test-helper.js'; | ||
|
||
describe('Profile | Acceptance | Application | Share Profile Route ', function () { | ||
let server; | ||
|
||
beforeEach(async function () { | ||
server = await createServer(); | ||
}); | ||
|
||
describe('POST /api/users/{userId}/profile/share-reward', function () { | ||
describe('when profile reward exists and is linked to user', function () { | ||
it('should return a success code', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser().id; | ||
const profileReward = databaseBuilder.factory.buildProfileReward({ userId }); | ||
const campaignParticipation = databaseBuilder.factory.buildCampaignParticipation(); | ||
|
||
await databaseBuilder.commit(); | ||
const options = { | ||
method: 'POST', | ||
headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, | ||
url: `/api/users/${userId}/profile/share-reward`, | ||
payload: { | ||
data: { | ||
attributes: { | ||
profileRewardId: profileReward.id, | ||
campaignParticipationId: campaignParticipation.id, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(201); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when profile reward is not linked to user', function () { | ||
it('should return a 412 code', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser().id; | ||
const profileReward = databaseBuilder.factory.buildProfileReward(); | ||
const campaignParticipation = databaseBuilder.factory.buildCampaignParticipation(); | ||
|
||
await databaseBuilder.commit(); | ||
const options = { | ||
method: 'POST', | ||
headers: { authorization: generateValidRequestAuthorizationHeader(userId) }, | ||
url: `/api/users/${userId}/profile/share-reward`, | ||
payload: { | ||
data: { | ||
attributes: { | ||
profileRewardId: profileReward.id, | ||
campaignParticipationId: campaignParticipation.id, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(412); | ||
}); | ||
}); | ||
}); |
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