From d6e187e9dff7038569975def9d13ef482834a7da Mon Sep 17 00:00:00 2001 From: Bikrant Jajware Date: Sat, 7 Oct 2023 14:53:25 +0530 Subject: [PATCH 1/6] docs: update openapi definition for ecommerce module --- api/src/modules/ecommerce/api/ecommerce-routes.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/api/src/modules/ecommerce/api/ecommerce-routes.ts b/api/src/modules/ecommerce/api/ecommerce-routes.ts index e498cdf0..53b693d7 100644 --- a/api/src/modules/ecommerce/api/ecommerce-routes.ts +++ b/api/src/modules/ecommerce/api/ecommerce-routes.ts @@ -80,15 +80,6 @@ import { getEcommerceCart } from '../utils/get-ecommerce-cart'; * $ref: '#/definitions/MockEcommerceProduct' */ -/** - * @openapi - * definitions: - * MockEcommerceCartList: - * type: array - * items: - * $ref: '#/definitions/MockEcommerceCart' - */ - module.exports = function (app: core.Express) { /** * @openapi @@ -118,12 +109,12 @@ module.exports = function (app: core.Express) { * parameters: * - in: path * name: qty - * description: The number of carts you want + * description: The number of products you want in your cart * responses: * '200': * description: OK * schema: - * $ref: '#/definitions/MockEcommerceCartList' + * $ref: '#/definitions/MockEcommerceCart' */ app.get('/ecommerce/cart/:qty', (req: Request, res: Response) => { const ecommerceCart = getEcommerceCart(req); From 58d36b95b3d81bd8327d7255983d72d77b232905 Mon Sep 17 00:00:00 2001 From: Elijah Soladoye Date: Fri, 13 Oct 2023 02:00:29 +0100 Subject: [PATCH 2/6] docs: integrating mocked-api with angular --- docs/integrations/ANGULAR.md | 299 +++++++++++++++++++++++++++++++++++ 1 file changed, 299 insertions(+) create mode 100644 docs/integrations/ANGULAR.md diff --git a/docs/integrations/ANGULAR.md b/docs/integrations/ANGULAR.md new file mode 100644 index 00000000..fe63b3fb --- /dev/null +++ b/docs/integrations/ANGULAR.md @@ -0,0 +1,299 @@ +# Integrating Mocked API with Angular + +Mocked API offers a diverse range of mocked data and API endpoints to support various frontend systems. If you don't have a backend application ready to support your frontend application, using Mocked API is a solid option. In this guide, we'll walk you through the process of integrating Mocked API with an Angular application. + +## Prerequisites + +Before we dive into the frontend integration, make sure your Mocked API server is up and running. Here are the steps to ensure the server is running: + +1. **Rename Environment Variable File**: + - Rename the environment variable file from `/api/.env.example` to `/api/.env`. + - Open the `/api/.env` file and ensure that Swagger is enabled by setting `ENABLE_SWAGGER=true`. + +2. **Start the Server**: + - Open your terminal or command prompt and navigate to the project directory. + - Run the following commands to start the server using either npm or yarn: + + ``` + npm install + npm run serve + ``` + + or + + ``` + yarn install + yarn serve + ``` + + If everything goes according to plan, you should see a message indicating that the Mock API is running on port 3000, and you can access it via your browser at `http://localhost:3000`. You can open this up and check out the available API endpoints Mocked API has to offer. Take note of this URL as you'll use it to connect to your application. + +## Integration Steps + +For this guide, we'll use Angular, which provides built-in tools and techniques to make the API integration process straightforward. Here's a step-by-step guide on how to consume Mocked API in an Angular application: + +### 1. Create an Angular Project + +If you haven't already, create a new Angular project using the Angular CLI. Run the following command to create a new project: + +```bash +ng new mocked-app +``` + +### 2. Define a Service + +Services in Angular are used to encapsulate the code that interacts with APIs. Create a service by running the following command: + +```bash +ng generate service services/mocked-api +``` + +This will create a file named `mocked-api.service.ts` in your project's `services/` directory. + +### 3. Import HttpClientModule + +To make HTTP requests, you'll need to import the `HttpClientModule` module in your app. Open the `src/app/app.module.ts` file and add the following import: + +```typescript +import { HttpClientModule } from "@angular/common/http"; +``` + +Then, add `HttpClientModule` to the `imports` array in the `@NgModule` decorator. + +Your file should look like this: +```typescript +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; +import { HttpClientModule } from '@angular/common/http'; + +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; + +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule, + AppRoutingModule, + HttpClientModule + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` + +### 4. Service Implementation + +In your service (e.g., `services/mocked-api.service.ts`), define methods to interact with the API. For this guide, we'll use the `/quotes` endpoint as an example. Here's a snippet of how to set up the service: + +```typescript +import { Injectable } from "@angular/core"; +import { HttpClient } from "@angular/common/http"; + +@Injectable({ + providedIn: "root", +}) +export class MockedApiService { + baseURL = "/api"; + // You can switch "/api" with the Mocked API Live server URL. + + fetchQuotes(quantity: number = 10) { + return this.http.get(`${this.baseURL}/quotes/${quantity}`); + } + + fetchRandomQuote() { + return this.http.get(`${this.baseURL}/quotes/random`); + } + + constructor(private http: HttpClient) {} +} +``` + +### 5. Proxy Configuration + +To avoid CORS issues when making requests to a server, you could set up a proxy. To to do this, create a `proxy.config.json` file in the project's root directory and add the following content: + +```json +{ + "/api/*": { + "target": "http://localhost:3000", + "secure": false, + "logLevel": "debug", + "pathRewrite": {"^/api" : ""} + } +} +``` +Essentially, what this does is to forward whatever request that comes to `/api/*` to be forwarded to `http://localhost:3000`, our backend server. Next, open the `angular.json` file in the project's root directory and add the following configuration under the `serve` section: + +```json +... + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "configurations": { + ... + "development": { + "browserTarget": "mocked-app:build:development", + "proxyConfig": "src/proxy.config.json", // add this in. + ... + } + }, + ... + }, +... +``` + +### 6. Component Usage + +In your Angular component (`src/app/app.component.ts`), you can use the service to fetch data and display it in your application. Here's an example of how to use the service: + +```typescript +import { Component, OnInit } from '@angular/core'; +import { MockedApiService } from './services/mocked-api.service'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.css'] +}) +export class AppComponent implements OnInit { + quotes: any; + randomQuote: any + + ngOnInit(): void { + this.mockedApiService.fetchQuotes().subscribe((data) => { + this.quotes = data; + }); + } + + getRandomQuote() { + this.mockedApiService.fetchRandomQuote().subscribe((data) => { + this.randomQuote = data; + }); + } + + constructor(private mockedApiService: MockedApiService) { } +} +``` + +### 7. Display Data + +Use Angular templates (HTML) to display the fetched data in your component's view. For example, in `src/app/app-component.component.html`: + +```html +
+
+
QuotesApp
+
+
+

Here are a few quotes to give you some insights...

+

+ Generate a random quote: + +

+
+

{{randomQuote?.quote || 'Press the button above'}}

+

+ -{{randomQuote?.author}} +

+
+
+
+

{{quote.quote}}

+

-{{quote.author}}

+
+
+
+
+``` + +### 8. Apply CSS Styles + +To style your Angular application, add the following CSS rules in the `src/app/app-component.component.css` file and in the `src/styles.css` file. + + +```css +/* src/app/app-component.component.css */ + .header { + padding: 20px; + background-color: black; + color: #fff; + } + + .content { + padding: 20px 40px; + } + + .content p { + margin-bottom: 10px; + } + + .quote-btn { + padding: 10px; + margin-left: 10px; + background-color: black; + color: #fff; + outline: none; + border: none; + cursor: pointer; + border-radius: 5px; + } + + .quotes { + display: flex; + gap: 10px; + flex-wrap: wrap; + align-items: center; + } + + .quote { + border: 1px solid #eee; + padding: 15px; + border-radius: 10px; + max-width: 500px; + } + + @media screen and (max-width: 800px) { + .quotes { + justify-content: center; + } + .quote { + min-width: 100%; + } + } + + .random-quote { + border: 1px solid #eee; + padding: 15px; + border-radius: 10px; + margin-bottom: 30px; + } + + .author { + font-weight: 600; + font-style: italic; + } +``` + +```css +/* src/styles.css */ +body { + margin: 0px !important; +} +``` + +### 9. Error Handling + +Don't forget to handle errors, such as network issues or API failures, in your service and component. + +### 10. Testing + +Test your Angular application to ensure that it correctly consumes the Mocked API and displays data. + +If you want to work with a production server, simply replace `'/api/'` with the actual URL of the live server base URL you want to consume. Additionally, handle error cases appropriately and consider adding loading indicators while data is being fetched. + +Have fun with other API Endpoints. +Cheers 😊🥂✨. \ No newline at end of file From a8c323193ce245c7bc076f54747a3aa5181bf4f1 Mon Sep 17 00:00:00 2001 From: Elijah Soladoye Date: Fri, 13 Oct 2023 03:25:12 +0100 Subject: [PATCH 3/6] docs: swager docs routing --- .all-contributorsrc | 30 ++++++++++- .github/workflows/main_mockedapiserver.yml | 57 +++++++++++++++++++++ README.md | 7 ++- api/.env.example | 2 +- api/app.ts | 8 ++- api/netlify.toml | 3 ++ api/src/modules/countries/data/provinces.ts | 15 ++---- marketing-site/package.json | 4 +- 8 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/main_mockedapiserver.yml create mode 100644 api/netlify.toml diff --git a/.all-contributorsrc b/.all-contributorsrc index 2b6b221a..b1bc95e1 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -446,6 +446,33 @@ "contributions": [ "code" ] + }, + { + "login": "PalaniappanC", + "name": "Palaniappan", + "avatar_url": "https://avatars.githubusercontent.com/u/45911913?v=4", + "profile": "https://github.com/PalaniappanC", + "contributions": [ + "code" + ] + }, + { + "login": "suppergerrie2", + "name": "Suppergerrie2", + "avatar_url": "https://avatars.githubusercontent.com/u/15769860?v=4", + "profile": "http://suppergerrie2.com", + "contributions": [ + "code" + ] + }, + { + "login": "dipushrestha", + "name": "Dipendra Shrestha", + "avatar_url": "https://avatars.githubusercontent.com/u/36785868?v=4", + "profile": "https://github.com/dipushrestha", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, @@ -453,5 +480,6 @@ "repoType": "github", "repoHost": "https://github.com", "projectName": "Mocked-API", - "projectOwner": "ageddesi" + "projectOwner": "ageddesi", + "commitType": "docs" } diff --git a/.github/workflows/main_mockedapiserver.yml b/.github/workflows/main_mockedapiserver.yml new file mode 100644 index 00000000..161931a7 --- /dev/null +++ b/.github/workflows/main_mockedapiserver.yml @@ -0,0 +1,57 @@ +# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy +# More GitHub Actions for Azure: https://github.com/Azure/actions + +name: Build and deploy Node.js app to Azure Web App - MockedAPIServer + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js version + uses: actions/setup-node@v1 + with: + node-version: '18.x' + + - name: npm install, build, and test + run: | + cd api + npm install + npm run build --if-present + npm run test --if-present + + - name: Upload artifact for deployment job + uses: actions/upload-artifact@v2 + with: + name: node-app + path: . + + deploy: + runs-on: ubuntu-latest + needs: build + environment: + name: 'Production' + url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} + + steps: + - name: Download artifact from build job + uses: actions/download-artifact@v2 + with: + name: node-app + + - name: 'Deploy to Azure Web App' + id: deploy-to-webapp + uses: azure/webapps-deploy@v2 + with: + app-name: 'MockedAPIServer' + slot-name: 'Production' + publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_4CDBE670B01E4899A27A3085FC82BD91 }} + package: . diff --git a/README.md b/README.md index c36beb6f..2580b3a2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-48-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors-)

@@ -176,6 +176,11 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Christa
Christa

📖 Bruno Vilar
Bruno Vilar

📖 Vitor
Vitor

💻 + Palaniappan
Palaniappan

💻 + + + Suppergerrie2
Suppergerrie2

💻 + Dipendra Shrestha
Dipendra Shrestha

💻 diff --git a/api/.env.example b/api/.env.example index b0bd1998..443f3ae7 100644 --- a/api/.env.example +++ b/api/.env.example @@ -6,4 +6,4 @@ SENTRY_DSN=https://23423423.ingest.sentry.io/234234 ENABLE_SENTRY=false ENABLE_RATE_LIMIT=false ENABLE_MORGAN_LOGGING=false -ENABLE_SWAGGER=false \ No newline at end of file +ENABLE_SWAGGER=true \ No newline at end of file diff --git a/api/app.ts b/api/app.ts index 95d9eecb..2432a360 100644 --- a/api/app.ts +++ b/api/app.ts @@ -49,6 +49,12 @@ app.get('/full-status', (req, res) => { app.use(cors()); // enabling CORS for all requests; -if (process.env.ENABLE_SWAGGER === 'true') initSwagger(app); // setup Swagger; +if (process.env.ENABLE_SWAGGER === 'true'){ + initSwagger(app); // setup Swagger; +} else { + app.get('/', (req, res) => { + res.status(200).send('Welcome to the Mocked API') + }) +} export default app; diff --git a/api/netlify.toml b/api/netlify.toml new file mode 100644 index 00000000..cb4071d2 --- /dev/null +++ b/api/netlify.toml @@ -0,0 +1,3 @@ +[build] + command = "npm install && npm run build" + functions = "functions" diff --git a/api/src/modules/countries/data/provinces.ts b/api/src/modules/countries/data/provinces.ts index b9ce6599..572c556a 100644 --- a/api/src/modules/countries/data/provinces.ts +++ b/api/src/modules/countries/data/provinces.ts @@ -2741,20 +2741,13 @@ const provincesList = [ { country: 'Nepal', provinces: [ + 'Koshi', + 'Madhesh', 'Bagmati', - 'Bheri', - 'Dhawalagiri', 'Gandaki', - 'Janakpur', - 'Karnali', - 'Kosi', 'Lumbini', - 'Mahakali', - 'Mechi', - 'Narayani', - 'Rapti', - 'Sagarmatha', - 'Seti', + 'Karnali', + 'Sudurpashchim', ], }, { diff --git a/marketing-site/package.json b/marketing-site/package.json index cec1a310..4f4ab50f 100644 --- a/marketing-site/package.json +++ b/marketing-site/package.json @@ -10,8 +10,8 @@ "astro": "astro" }, "devDependencies": { - "@astrojs/tailwind": "^1.0.0", - "astro": "^1.0.8", + "@astrojs/tailwind": "^5.0.0", + "astro": "^3.2.0", "sass": "^1.55.0" }, "dependencies": { From 8fdc8039c8d27b0ecdab7b0268199d7c1a90dbf5 Mon Sep 17 00:00:00 2001 From: fadkeabhi <31249309+fadkeabhi@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:53:18 +0530 Subject: [PATCH 4/6] feat: add new route facts --- api/src/modules/facts/api/facts-routes.ts | 52 ++++ api/src/modules/facts/data/facts.ts | 276 ++++++++++++++++++ .../facts/test/api/facts-routes.test.ts | 26 ++ 3 files changed, 354 insertions(+) create mode 100644 api/src/modules/facts/api/facts-routes.ts create mode 100644 api/src/modules/facts/data/facts.ts create mode 100644 api/src/modules/facts/test/api/facts-routes.test.ts diff --git a/api/src/modules/facts/api/facts-routes.ts b/api/src/modules/facts/api/facts-routes.ts new file mode 100644 index 00000000..567bd416 --- /dev/null +++ b/api/src/modules/facts/api/facts-routes.ts @@ -0,0 +1,52 @@ +import { Request, Response } from 'express'; +import * as core from 'express-serve-static-core'; +import { getQtyFromRequest } from '../../../utils/route-utils'; +import facts from '../data/facts'; + +module.exports = function (app: core.Express) { + /** + * @openapi + * '/facts/random': + * get: + * tags: + * - Facts + * summary: Get a random fact from the database + * responses: + * '200': + * description: OK + * schema: + * type: object + * example: { fact: '', category: ''} + */ + app.get('/facts/random', (req: Request, res: Response) => { + const fact = facts[Math.floor(Math.random() * facts.length)]; + res.json(fact); + }); + + /** + * @openapi + * '/facts/{qty}': + * get: + * tags: + * - Facts + * summary: Get a list of all facts from the database + * parameters: + * - in: path + * name: qty + * description: The amount of results you would like returned + * default: 10 + * type: number + * responses: + * '200': + * description: OK + * schema: + * type: array + * items: + * type: object + * example: { fact: '', category: ''} + */ + app.get('/facts/:qty', (req: Request, res: Response) => { + const qty = getQtyFromRequest(req); + res.json(qty >= facts.length ? facts : facts.slice(0, qty)); + }); +}; diff --git a/api/src/modules/facts/data/facts.ts b/api/src/modules/facts/data/facts.ts new file mode 100644 index 00000000..635f9cbb --- /dev/null +++ b/api/src/modules/facts/data/facts.ts @@ -0,0 +1,276 @@ +const facts = [ + { + fact: 'Dalmatians are born without spots! They are born with plain white coats with their first spots appearing after they are 1week old.', + category: 'dog' + }, + { + fact: 'Dogs sweat through their foot pads to help keep them cool. They also keep cool by panting.', + category: 'dog' + }, + { + fact: 'Greyhounds are the world\'s fastest dogs with the ability to reach up to 45 mph.', + category: 'dog' + }, + { + fact: 'Every dog has a unique nose print with no two alike.', + category: 'dog' + }, + { + fact: 'The Basenji, an African wolf dog, does not bark in a normal way but may yodel or scream when excited!', + category: 'dog' + }, + { + fact: 'Snoopy, from Charles M. Schultz\'s "Peanuts" comic strip, is a beagle.', + category: 'dog' + }, + { + fact: 'A dog\'s sense of smell is 1000 times greater than a human!', + category: 'dog' + }, + { + fact: 'Nine percent of dog owners will have a birthday party for their pet.', + category: 'dog' + }, + { + fact: 'Dogs have 28 baby teeth and 42 permanent teeth.', + category: 'dog' + }, + { + fact: 'Cats have 32 muscles in each ear.', + category: 'cat' + }, + { + fact: 'Cats have 4 rows of whiskers.', + category: 'cat' + }, + { + fact: 'Cats have no collarbone, which is one reason they are so flexible.', + category: 'cat' + }, + { + fact: 'Cats spend approximately 30% of their waking hours grooming themselves.', + category: 'cat' + }, + { + fact: '"American Shorthair" is the designation reserved for pedigreed cats, while similar-looking cats of mixed or unknown origin are called "domestic shorthairs."', + category: 'cat' + }, + { + fact: 'Feline\'s jaws cannot move sideways.', + category: 'cat' + }, + { + fact: 'Cats have over one hundred vocal sounds, while dogs have about ten!', + category: 'cat' + }, + { + fact: 'Cat whiskers are so sensitive they can detect the slightest change in air current.', + category: 'cat' + }, + { + fact: 'Cats have 26 baby teeth and 30 permanent teeth.', + category: 'cat' + }, + { + fact: 'Fleas can jump 350 times its body length.', + category: 'animal' + }, + { + fact: 'Hummingbirds are the only birds that can fly backwards.', + category: 'animal' + }, + { + fact: 'Crocodiles cannot stick their tongue out.', + category: 'animal' + }, + { + fact: 'Starfish do not have a brain.', + category: 'animal' + }, + { + fact: 'Slugs have 4 noses.', + category: 'animal' + }, + { + fact: 'Only female mosquitoes bite.', + category: 'animal' + }, + { + fact: 'Polar bear skin is black!', + category: 'animal' + }, + { + fact: 'The only mammal capable of flight is the bat.', + category: 'animal' + }, + { + fact: 'A newborn kangaroo is the size of a lima bean.', + category: 'animal' + }, + { + fact: 'Coconuts, peaches, and pineapples are all considered to be berries.', + category: 'fruit' + }, + { + fact: 'At one point in time, blackberry juice was used to dye clothes.', + category: 'fruit' + }, + { + fact: 'Coffee beans aren’t really beans at all. Instead, they’re actually fruit pits.', + category: 'fruit' + }, + { + fact: 'Pomology: the science of growing fruits.', + category: 'fruit' + }, + { + fact: 'Humans and bananas have 50% of the same DNA.', + category: 'fruit' + }, + { + fact: 'The stickers placed on fruits are made out of edible paper, meaning that they are, technically, able to be consumed.', + category: 'fruit' + }, + { + fact: 'The Durian fruit is the world’s worst smelling fruit.', + category: 'fruit' + }, + { + fact: 'Kiwis, at one time, were known as Chinese Gooseberries.', + category: 'fruit' + }, + { + fact: 'Plums, pears, peaches, and apples are all apart of the Rose Family.', + category: 'fruit' + }, + { + fact: 'Pomegranates can have up to 1,400 seeds.', + category: 'fruit' + }, + { + fact: 'A mango tree can grow to be 100 feet tall.', + category: 'fruit' + }, + { + fact: 'Apples are 25% air which is why, when placed in water, they float.', + category: 'fruit' + }, + { + fact: 'Many Japanese farmers grow watermelon in the shape of a cube in order to make more space in refrigerators.', + category: 'fruit' + }, + { + fact: 'Starfruit can also be called Carambola.', + category: 'fruit' + }, + { + fact: 'Explorers once used watermelons as canteens.', + category: 'fruit' + }, + { + fact: 'Orange peels have four times more fiber than oranges themselves.', + category: 'fruit' + }, + { + fact: 'Strawberries typically have around 200 seeds. They’re also the only fruit with seeds on the outside.', + category: 'fruit' + }, + { + fact: 'There are more than 1,000 known species of blackberries.', + category: 'fruit' + }, + { + fact: 'Dragon Fruit is full of vitamin C and is even said to help reduce acne.', + category: 'fruit' + }, + { + fact: 'Lemons are a cross between sour oranges and citrons.', + category: 'fruit' + }, + { + fact: 'Most lime species are natives of Asia.', + category: 'fruit' + }, + { + fact: 'Hawaii is the only state in the U.S. that grows papayas to market and sell.', + category: 'fruit' + }, + { + fact: 'China sells and produces more tangerines that any other country.', + category: 'fruit' + }, + { + fact: 'In Latin, the word pomegranate means “apple with many seeds.”', + category: 'fruit' + }, + { + fact: 'Some fruits that most people haven’t ever heard of–but are worth learning more about–include the following: cotton candy grapes, lemon cucumbers, kiwi berries, cherimoya, jackfruit, pomelo, water apples, etc.', + category: 'fruit' + }, + { + fact: 'Grapes, when heated in a microwave, will actually explode.', + category: 'fruit' + }, + { + fact: 'The fruit salad tree is a tree that can grow up to 7 different fruits.', + category: 'fruit' + }, + { + fact: 'Tomatoes have more genes than we do.', + category: 'fruit' + }, + { + fact: 'Miracle fruit is a fruit that, when eaten, causes sour foods to taste sweet for at least an hour or two after consumption.', + category: 'fruit' + }, + { + fact: 'As pineapples were so expensive in colonial times, people would simply rent these flavorful fruits and show them off to others as a sign of wealth.', + category: 'fruit' + }, + { + fact: 'Space is completely silent because there is no atmosphere.', + category: 'space' + }, + { + fact: 'Our solar system is around 4.571 billion years old.', + category: 'space' + }, + { + fact: 'The highest mountain found in our solar system is on Mars.', + category: 'space' + }, + { + fact: 'It would take a modern spacecraft 450 million years to travel to the center of the Milky Way.', + category: 'space' + }, + { + fact: 'Mars is often described as the "Red Planet" because the iron oxide prevalent on its surface gives it a reddish appearance.', + category: 'space' + }, + { + fact: 'Uranus spins sideways.', + category: 'space' + }, + { + fact: 'There is water in space.', + category: 'space' + }, + { + fact: 'The moon is the only other world humans have ever set foot on.', + category: 'space' + }, + { + fact: 'A space station can provide nearly everything humans need. However, current space stations cannot simulate gravity which our bodies need.', + category: 'space' + }, + { + fact: "Mars' sunsets are blue.", + category: 'space' + }, + { + fact: 'The hottest planet in our solar system is Venus.', + category: 'space' + }, +] + +export default facts; diff --git a/api/src/modules/facts/test/api/facts-routes.test.ts b/api/src/modules/facts/test/api/facts-routes.test.ts new file mode 100644 index 00000000..1f076354 --- /dev/null +++ b/api/src/modules/facts/test/api/facts-routes.test.ts @@ -0,0 +1,26 @@ +import request from 'supertest'; +import app from '../../../../../app'; + +describe('facts api endpoints', () => { + describe('GET /facts/:qty', () => { + it('should the correct number of facts', async () => { + const qty = 5; + const response = await request(app).get(`/facts/${qty}`).expect(200).expect('Content-Type', /json/); + + expect(response.body).toBeInstanceOf(Array); + expect(response.body.length).toBe(qty); + expect(response.body[0]).toHaveProperty('fact'); + expect(response.body[0]).toHaveProperty('category'); + }); + }); + + describe('GET /facts/random', () => { + it('should return a random fact', async () => { + const response = await request(app).get('/facts/random').expect(200).expect('Content-Type', /json/); + + expect(response.body).toBeInstanceOf(Object); + expect(response.body).toHaveProperty('fact'); + expect(response.body).toHaveProperty('category'); + }); + }); +}); From 5c8db9e40ac7b745eee240e7699b88428ed090dd Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:37:50 +0000 Subject: [PATCH 5/6] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2580b3a2..e7365778 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -[![All Contributors](https://img.shields.io/badge/all_contributors-51-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-52-orange.svg?style=flat-square)](#contributors-)

@@ -181,6 +181,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Suppergerrie2
Suppergerrie2

💻 Dipendra Shrestha
Dipendra Shrestha

💻 + Elijah Soladoye
Elijah Soladoye

💻 📖 From ae9a2aaf652ad488c6994a47fdf2ee9d2cad3b93 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 16 Oct 2023 09:37:51 +0000 Subject: [PATCH 6/6] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b1bc95e1..6d0065d6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -473,6 +473,16 @@ "contributions": [ "code" ] + }, + { + "login": "shodown96", + "name": "Elijah Soladoye", + "avatar_url": "https://avatars.githubusercontent.com/u/41167893?v=4", + "profile": "http://elijahsoladoye.vercel.app", + "contributions": [ + "code", + "doc" + ] } ], "contributorsPerLine": 7,