fix signin signout and apply the new style
This commit is contained in:
@@ -52,6 +52,9 @@ export async function createVehicle(companyId: string, overrides: Record<string,
|
||||
dailyRate: 500,
|
||||
status: 'AVAILABLE',
|
||||
isPublished: true,
|
||||
pickupLocations: ['Casablanca'],
|
||||
allowDifferentDropoff: false,
|
||||
dropoffLocations: [],
|
||||
...overrides,
|
||||
} as any,
|
||||
})
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import request from 'supertest'
|
||||
import { createApp } from '../../app'
|
||||
|
||||
const app = createApp()
|
||||
|
||||
function uniqueEmail(prefix: string) {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}@test.com`
|
||||
}
|
||||
|
||||
describe('Company signup API', () => {
|
||||
it('creates new accounts with a 90-day trial period', async () => {
|
||||
const startedAt = Date.now()
|
||||
|
||||
const res = await request(app)
|
||||
.post('/api/v1/auth/company/signup')
|
||||
.send({
|
||||
firstName: 'Trial',
|
||||
lastName: 'Owner',
|
||||
email: uniqueEmail('trial-owner'),
|
||||
password: 'Password123!',
|
||||
companyName: `Trial Cars ${Date.now()}`,
|
||||
legalForm: 'LLC',
|
||||
registrationNumber: `REG-${Date.now()}`,
|
||||
streetAddress: '123 Main Street',
|
||||
city: 'Casablanca',
|
||||
country: 'Morocco',
|
||||
zipCode: '20000',
|
||||
companyPhone: '+212600000000',
|
||||
yearsActive: '1',
|
||||
preferredLanguage: 'en',
|
||||
plan: 'STARTER',
|
||||
billingPeriod: 'MONTHLY',
|
||||
currency: 'MAD',
|
||||
paymentProvider: 'AMANPAY',
|
||||
})
|
||||
|
||||
expect(res.status).toBe(201)
|
||||
|
||||
const trialEndsAt = new Date(res.body.data.trialEndsAt).getTime()
|
||||
const trialDurationDays = (trialEndsAt - startedAt) / (24 * 60 * 60 * 1000)
|
||||
|
||||
expect(trialDurationDays).toBeGreaterThan(89.9)
|
||||
expect(trialDurationDays).toBeLessThan(90.1)
|
||||
})
|
||||
})
|
||||
@@ -64,11 +64,17 @@ describe('Vehicles API', () => {
|
||||
licensePlate: `TEST-${Date.now()}`,
|
||||
category: 'COMPACT',
|
||||
dailyRate: 400,
|
||||
pickupLocations: ['Casablanca Airport', 'Casablanca Downtown'],
|
||||
allowDifferentDropoff: true,
|
||||
dropoffLocations: ['Rabat Downtown'],
|
||||
})
|
||||
|
||||
expect(res.status).toBe(201)
|
||||
expect(res.body.data.make).toBe('Honda')
|
||||
expect(res.body.data.model).toBe('Civic')
|
||||
expect(res.body.data.pickupLocations).toEqual(['Casablanca Airport', 'Casablanca Downtown'])
|
||||
expect(res.body.data.allowDifferentDropoff).toBe(true)
|
||||
expect(res.body.data.dropoffLocations).toEqual(['Rabat Downtown'])
|
||||
})
|
||||
|
||||
it('returns 400 for missing required fields', async () => {
|
||||
@@ -116,6 +122,24 @@ describe('Vehicles API', () => {
|
||||
expect(res.body.data.notes).toBe('Updated via integration test')
|
||||
})
|
||||
|
||||
it('updates pickup and drop-off settings', async () => {
|
||||
const vehicle = await createVehicle(companyId)
|
||||
|
||||
const res = await request(app)
|
||||
.patch(`/api/v1/vehicles/${vehicle.id}`)
|
||||
.set(authHeader(token))
|
||||
.send({
|
||||
pickupLocations: ['Casablanca Airport'],
|
||||
allowDifferentDropoff: true,
|
||||
dropoffLocations: ['Rabat Downtown', 'Marrakech Center'],
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(res.body.data.pickupLocations).toEqual(['Casablanca Airport'])
|
||||
expect(res.body.data.allowDifferentDropoff).toBe(true)
|
||||
expect(res.body.data.dropoffLocations).toEqual(['Rabat Downtown', 'Marrakech Center'])
|
||||
})
|
||||
|
||||
it('sets isPublished=false when status=MAINTENANCE', async () => {
|
||||
const vehicle = await createVehicle(companyId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user