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
if (response.statusCode === 200) { | |
return res | |
.status(200) | |
.header('set-cookie', loginResponse.headers['set-cookie']) | |
.send(); | |
} |
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
if (response.status === 200) { | |
return res.send(200, {headers: {'set-cookie': loginResponse.headers['set-cookie']}}); | |
} |
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
it('should send OK with correct headers', () => { | |
expect(response.send).toHaveBeenCalledWith(200, {headers: {'set-cookie': externalResponseHeaders['set-cookie']}}); | |
expect(response.send).toHaveBeenCalledTimes(1); | |
}); |
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
it('should send OK with correct headers', () => { | |
expect(response.status).toHaveBeenCalledWith(200); | |
expect(response.header).toHaveBeenCalledWith('set-cookie', externalResponseHeaders['set-cookie']); | |
expect(response.send).toHaveBeenCalledTimes(1); | |
}); |
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
describe('when user was successfully logged in', () => { | |
const externalResponseHeaders = { | |
'set-cookie': 'valid-cookie-from-external-endpoint', | |
}; | |
beforeEach(async () => { | |
simulateSucessfulLoginResponse(externalResponseHeaders); // implementation should not be relevant for this demonstration | |
await executeAction(); // implementation should not be relevant for this demonstration | |
}); |
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
app.post('/v1/login', async (req, res) => { | |
try { | |
const response = await requestPromise.post({ | |
uri: `${API_BASE_URL}/api/oauth2/auth?${req.body.formQuery}`, | |
body: req.body, | |
json: true, | |
strictSSL: false, | |
resolveWithFullResponse: true, | |
simple: 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
const ordinaryUser = new User(['moderator']); | |
const adminUser = new AdminUser(['moderator','admin']); |
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
class User { | |
constructor(roles) { | |
this.roles = roles; | |
} | |
getRoles() { | |
return this.roles; | |
} | |
} | |
class AdminUser extends User {} |
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
export class PopulatedUserList extends Component { | |
render() { | |
return ( | |
<div> | |
<UserList>{ | |
({users}) => { | |
return <ul> | |
{users.map((user, index) => <li key={index}>{user.id}: {user.name} {user.surname}</li>)} | |
</ul> |
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
export class UserTable extends Component { | |
render() { | |
return ( | |
<div> | |
<UserList>{ | |
({users}) => { | |
return <table> | |
<thead> | |
<tr> |