-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for put data with same email
relates #25
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,6 +189,13 @@ describe('Admin, Put project', () => { | |
githubLink: 'github link', | ||
cohortId: 1, | ||
}; | ||
const duplicateData = { | ||
name: 'Rehab', | ||
email: '[email protected]', | ||
imgUrl: 'https://avatars3.githubusercontent.com/u/49806841?s=460&v=4', | ||
githubLink: 'https://github.com/rehabas', | ||
cohortId: 1, | ||
}; | ||
|
||
test('PUT Route /alumni/1 status 200, json header, put data ', (done) => { | ||
request(app) | ||
|
@@ -219,6 +226,41 @@ describe('Admin, Put project', () => { | |
}); | ||
}); | ||
|
||
test('PUT Route /alumni/1 status 200, json header, put data with same email', (done) => { | ||
request(app) | ||
.put('/api/v1/alumni/1') | ||
.send({ | ||
name: 'sara', | ||
email: '[email protected]', | ||
imgUrl: 'https://avatars3.githubusercontent.com/u/49806841?s=460&v=4', | ||
githubLink: 'https://github.com/rehabas', | ||
cohortId: 1, | ||
}) | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.end(async (err, res) => { | ||
if (err) return done(err); | ||
const { | ||
data: { message }, | ||
} = res.body; | ||
const { rows } = await connection.query( | ||
'SELECT * from student WHERE id = 1', | ||
); | ||
expect(rows).toHaveLength(1); | ||
expect(rows[0]).toEqual({ | ||
id: 1, | ||
name: 'sara', | ||
email: '[email protected]', | ||
img_url: | ||
'https://avatars3.githubusercontent.com/u/49806841?s=460&v=4', | ||
github_link: 'https://github.com/rehabas', | ||
cohort_id: 1, | ||
}); | ||
expect(message).toBe("Student's data updated successfully"); | ||
done(); | ||
}); | ||
}); | ||
|
||
test('PUT Route /alumni/11 status 404, json header, put data ', (done) => { | ||
request(app) | ||
.put('/api/v1/alumni/11') | ||
|
@@ -259,4 +301,22 @@ describe('Admin, Put project', () => { | |
done(); | ||
}); | ||
}); | ||
|
||
test('PUT Route /alumni/1 status 409, json header, put data ', (done) => { | ||
request(app) | ||
.put('/api/v1/alumni/1') | ||
.send(duplicateData) | ||
.expect(409) | ||
.expect('Content-Type', /json/) | ||
.end(async (err, res) => { | ||
if (err) return done(err); | ||
const { | ||
data: { message }, | ||
} = res.body; | ||
expect(message).toBe( | ||
`Key (email)=(${duplicateData.email}) already exists.`, | ||
); | ||
done(); | ||
}); | ||
}); | ||
}); |