Skip to content

Instantly share code, notes, and snippets.

View whtswrng's full-sized avatar

Tomáš Gold whtswrng

  • Brno
View GitHub Profile
if (response.statusCode === 200) {
return res
.status(200)
.header('set-cookie', loginResponse.headers['set-cookie'])
.send();
}
if (response.status === 200) {
return res.send(200, {headers: {'set-cookie': loginResponse.headers['set-cookie']}});
}
it('should send OK with correct headers', () => {
expect(response.send).toHaveBeenCalledWith(200, {headers: {'set-cookie': externalResponseHeaders['set-cookie']}});
expect(response.send).toHaveBeenCalledTimes(1);
});
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);
});
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
});
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,
});
const ordinaryUser = new User(['moderator']);
const adminUser = new AdminUser(['moderator','admin']);
@whtswrng
whtswrng / lsp.jsx
Last active October 23, 2018 11:35
class User {
constructor(roles) {
this.roles = roles;
}
getRoles() {
return this.roles;
}
}
class AdminUser extends User {}
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>
export class UserTable extends Component {
render() {
return (
<div>
<UserList>{
({users}) => {
return <table>
<thead>
<tr>