-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from atlp-rwanda/fix-google-auth
Fixes the API redirect issue on the same port during Google authentication
- Loading branch information
Showing
23 changed files
with
143 additions
and
58 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import request from 'supertest'; | ||
import { app, server } from '../index'; | ||
import { createConnection, getRepository} from 'typeorm'; | ||
import { cleanDatabase } from './test-assets/DatabaseCleanup'; | ||
import { Category } from '../entities/Category'; | ||
|
||
beforeAll(async () => { | ||
await createConnection(); | ||
}); | ||
|
||
jest.setTimeout(20000); | ||
|
||
afterAll(async () => { | ||
await cleanDatabase(); | ||
server.close(); | ||
}); | ||
|
||
|
||
describe('GET /categories', () => { | ||
it('should return all categories', async () => { | ||
const categoryRepository = getRepository(Category); | ||
await categoryRepository.save([ | ||
{ name: 'Category 1' }, | ||
{ name: 'Category 2' }, | ||
]); | ||
|
||
const response = await request(app).get('/product/categories'); | ||
console.log(response.error) | ||
expect(response.status).toBe(200); | ||
expect(response.body.status).toBe('success'); | ||
expect(response.body.categories).toHaveLength(2); | ||
expect(response.body.categories[0].name).toBe('Category 1'); | ||
expect(response.body.categories[1].name).toBe('Category 2'); | ||
}); | ||
|
||
it('should handle errors gracefully', async () => { | ||
const response = await request(app).get('/product/categories'); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.status).toBe('success'); | ||
expect(response.body.categories).toHaveLength(2); | ||
}); | ||
}); |
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
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Request, Response } from 'express'; | ||
import { getRepository } from 'typeorm'; | ||
import { Category } from '../../entities/Category'; | ||
|
||
export const getAllCategories = async (req: Request, res: Response) => { | ||
try { | ||
const categoryRepository = getRepository(Category); | ||
const categories = await categoryRepository.find({ | ||
relations: { | ||
products: true | ||
}, | ||
select: { | ||
products: { | ||
id: true | ||
} | ||
} | ||
}); | ||
|
||
res.status(200).json({ status: 'success', categories }); | ||
} catch (error) { | ||
console.error('Error fetching categories:', error); | ||
res.status(500).json({ status: 'error', message: 'Error fetching categories' }); | ||
} | ||
}; |
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
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
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
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
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
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
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
Oops, something went wrong.