refactor: use python instead of javascript

This commit is contained in:
Bjarke Sporring
2026-01-05 12:21:48 +01:00
parent e1b8d8418a
commit f11f5a4646
14 changed files with 550 additions and 735 deletions

View File

@@ -40,88 +40,78 @@ git commit -m "Initial commit" | Out-Null
# Commit 1: WIP user profile
$userProfile = @"
class UserProfile {
constructor(name, email) {
this.name = name;
this.email = email;
}
}
class UserProfile:
def __init__(self, name, email):
self.name = name
self.email = email
"@
Set-Content -Path "user-profile.js" -Value $userProfile
git add user-profile.js
Set-Content -Path "user_profile.py" -Value $userProfile
git add user_profile.py
git commit -m "WIP: user profile" | Out-Null
# Commit 2: Add validation (typo in message)
$userProfileWithValidation = @"
class UserProfile {
constructor(name, email) {
this.name = name;
this.email = email;
}
class UserProfile:
def __init__(self, name, email):
self.name = name
self.email = email
validate() {
if (!this.name || !this.email) {
throw new Error('Name and email are required');
}
return true;
}
}
def validate(self):
if not self.name or not self.email:
raise ValueError('Name and email are required')
return True
"@
Set-Content -Path "user-profile.js" -Value $userProfileWithValidation
git add user-profile.js
Set-Content -Path "user_profile.py" -Value $userProfileWithValidation
git add user_profile.py
git commit -m "add validaton" | Out-Null # Intentional typo
# Commit 3: Fix validation
$userProfileFixed = @"
class UserProfile {
constructor(name, email) {
this.name = name;
this.email = email;
}
class UserProfile:
def __init__(self, name, email):
self.name = name
self.email = email
validate() {
if (!this.name || !this.email) {
throw new Error('Name and email are required');
}
if (!this.email.includes('@')) {
throw new Error('Invalid email format');
}
return true;
}
}
def validate(self):
if not self.name or not self.email:
raise ValueError('Name and email are required')
if '@' not in self.email:
raise ValueError('Invalid email format')
return True
"@
Set-Content -Path "user-profile.js" -Value $userProfileFixed
git add user-profile.js
Set-Content -Path "user_profile.py" -Value $userProfileFixed
git add user_profile.py
git commit -m "fix validation bug" | Out-Null
# Commit 4: Add tests (another WIP commit)
$tests = @"
const assert = require('assert');
const UserProfile = require('./user-profile');
import unittest
from user_profile import UserProfile
describe('UserProfile', () => {
it('should validate correct user data', () => {
const user = new UserProfile('John', 'john@example.com');
assert.strictEqual(user.validate(), true);
});
class TestUserProfile(unittest.TestCase):
def test_validate_correct_user_data(self):
user = UserProfile('John', 'john@example.com')
self.assertTrue(user.validate())
it('should reject missing name', () => {
const user = new UserProfile('', 'john@example.com');
assert.throws(() => user.validate());
});
def test_reject_missing_name(self):
user = UserProfile('', 'john@example.com')
with self.assertRaises(ValueError):
user.validate()
it('should reject invalid email', () => {
const user = new UserProfile('John', 'invalid-email');
assert.throws(() => user.validate());
});
});
def test_reject_invalid_email(self):
user = UserProfile('John', 'invalid-email')
with self.assertRaises(ValueError):
user.validate()
if __name__ == '__main__':
unittest.main()
"@
Set-Content -Path "user-profile.test.js" -Value $tests
git add user-profile.test.js
Set-Content -Path "test_user_profile.py" -Value $tests
git add test_user_profile.py
git commit -m "WIP tests" | Out-Null
# Return to module directory