| Hosted URL | : | https://long-yak-baseball-cap.cyclic.app/api |
| Minimum Node version | : | 19.0.0 |
| Minimum PostgreSQL version | : | 12.12 |
This API allows users to retrieve, add, modify and delete data from the Northcoders News database. This database includes tables of users, topics, articles and comments.
To clone the repo, first open it on GitHub. Press the green button on screen that says "<> Code" and copy the link.
In your terminal, navigate to the directory into which you would like to clone the repo, and run git clone <REPO-URL>.
Run npm install in the terminal to install all dependencies.
The file at ./db/connection.js sets the environment variables for the repo based on a pair of .env files that you will need to prepare:
- Create two files in the root directory:
.env.testand.env.development - Set the content of
.env.developmenttoPGDATABASE=nc_news - Set the content of
.env.testtoPGDATABASE=nc_news_test - Add
.env.*to your.gitignorefile to ensure any other environment variables you may wish to add do not get pushed to GitHub.
Before you can seed, you need to create the database. To do this, simply run npm run setup-dbs in your console.
Simply run npm run seed and the database will be seeded.
Jest will seed the database for you automatically whenever you run your test suite, so long as you include this code at the top of your test file:
const db = require(`${__dirname}/../db/connection.js`); // the Pool object
const seed = require(`${__dirname}/../db/seeds/seed.js`); // invoking this seeds the database
const {
articleData,
commentData,
topicData,
userData
} = require(`${__dirname}/../db/data/test-data/index.js`); // all the data files
beforeEach(() => {
return seed({ topicData, userData, articleData, commentData }); // re-seed the database before each test
});
afterAll(() => {
return db.end(); // close the database connection after running the test suite
});To use Jest for testing this Express API, you need to install supertest as a dev dependency, and require it into the test suite.
Read the supertest docs for advice on how to create API tests.