docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build an authentication service that enables users to sign in using their Google accounts. The service should handle the complete OAuth flow, store user information, and provide access tokens for making authenticated requests.
File: auth.test.js
Description: Verify that OAuth strategy is properly configured
const passport = require('passport');
describe('OAuth Configuration', () => {
it('should have Google OAuth strategy registered', () => {
const strategy = passport._strategies['google'];
expect(strategy).toBeDefined();
expect(strategy.name).toBe('google');
});
});File: auth.test.js
Description: Verify that authentication callback processes tokens and profile
describe('OAuth Callback', () => {
it('should extract access token and user profile', (done) => {
const mockAccessToken = 'mock_access_token';
const mockRefreshToken = 'mock_refresh_token';
const mockProfile = {
id: '12345',
displayName: 'Test User',
emails: [{ value: 'test@example.com' }]
};
// Verify your callback extracts and stores tokens and profile
verifyCallback(mockAccessToken, mockRefreshToken, mockProfile, (err, user) => {
expect(err).toBeNull();
expect(user.googleId).toBe('12345');
expect(user.email).toBe('test@example.com');
expect(user.accessToken).toBe(mockAccessToken);
done();
});
});
});File: auth.test.js
Description: Verify that proper OAuth scopes are requested
describe('OAuth Scopes', () => {
it('should request profile and email scopes', () => {
const strategy = passport._strategies['google'];
expect(strategy._scope).toContain('profile');
expect(strategy._scope).toContain('email');
});
});Provides Google OAuth authentication strategies for Passport.js applications.
Express-compatible authentication middleware for Node.js.
Web application framework for Node.js.