Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grading PR #41

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
APP_SECRET=
SALT_ROUNDS=
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
dist
dist
.vscode
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

1 change: 0 additions & 1 deletion __tests__/auth.tests.js → __tests__/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ describe('auth routes', () => {

expect(res.body).toEqual({ id: '1', email: '[email protected]' });
});

});
17 changes: 11 additions & 6 deletions __tests__/categories.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import pool from '../lib/utils/pool.js';
import setup from '../data/setup.js';
import request from 'supertest';
import app from '../lib/app.js';
import Category from '../lib/Model/Category.js';
import Category from '../lib/models/Category.js';

describe('categories routes', () => {
beforeEach(() => {
Expand All @@ -13,15 +13,15 @@ describe('categories routes', () => {
pool.end();
});

it.skip('inserts a category into the categories table with POST', async () => {
it('inserts a category into the categories table with POST', async () => {
const category = {
category: 'housing',
};

const res = await request(app).post('/api/v1/categories').send(category);

expect(res.body).toEqual({
id: category.id,
id: expect.any(String), // matches any id
...category,
});
});
Expand All @@ -33,10 +33,15 @@ describe('categories routes', () => {

const res = await request(app).get(`/api/v1/categories/${category.id}`);

expect(res.body).toEqual(category);
// `{ ...category }` makes `Category` a plain, ol' Javascript object
expect(res.body).toEqual({ ...category });
});

it.skip('gets all categories with GET', async () => {
it('gets all categories with GET', async () => {
// The `uncategorized` category will be in the response,
// so we need to get it to add to our expectation
const category0 = await Category.getById(1);

const category1 = await Category.insert({
category: 'housing',
});
Expand All @@ -49,7 +54,7 @@ describe('categories routes', () => {

const res = await request(app).get('/api/v1/categories/');

expect(res.body).toEqual([category1, category2, category3]);
expect(res.body).toEqual([category0, category1, category2, category3]);
});

it('updates a category by id with PUT', async () => {
Expand Down
14 changes: 7 additions & 7 deletions __tests__/cities.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import pool from '../lib/utils/pool.js';
import setup from '../data/setup.js';
import request from 'supertest';
import app from '../lib/app.js';
import City from '../lib/Model/City.js';
import City from '../lib/models/City.js';

describe('demo routes', () => {
describe('cities routes', () => {
beforeEach(() => {
return setup(pool);
});
Expand Down Expand Up @@ -35,23 +35,23 @@ describe('demo routes', () => {
expect(res.body).toEqual([
{
id: '1',
...city1
...city1,
},
{
id: '2',
...city2
...city2,
},
{
id: '3',
...city3,
},
{
id: '4',
...city4
}
...city4,
},
]);
});

it('gets a city by id via GET', async () => {
const city1 = { city: 'Portland' };
const currentCity = await City.insert(city1);
Expand Down
16 changes: 0 additions & 16 deletions __tests__/elderly-assistance-services.test.js

This file was deleted.

113 changes: 57 additions & 56 deletions __tests__/resources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import pool from '../lib/utils/pool.js';
import setup from '../data/setup.js';
import request from 'supertest';
import app from '../lib/app.js';
import City from '../lib/Model/City.js';
import Category from '../lib/Model/Category.js';
import Resource from '../lib/Model/Resource.js';
import City from '../lib/models/City.js';
import Category from '../lib/models/Category.js';
import Resource from '../lib/models/Resource.js';

const resource = {
src_name: 'Tubman Family Crisis and Support Services',
src_description: 'We help people with stuff',
const mockResource1 = {
srcName: 'Tubman Family Crisis and Support Services',
srcDescription: 'We help people with stuff',
info: ['612-825-0000', '612-825-3333', '[email protected]'],
city_id: 1,
category_id: 1,
cityId: 1,
categoryId: 1,
tags: ['General', 'health', 'butter'],
};

const resource2 = {
src_name: 'Second Resource',
src_description: 'We do things',
const mockResource2 = {
srcName: 'Second Resource',
srcDescription: 'We do things',
info: ['612-000-0000', '612-000-3333', '[email protected]'],
city_id: 1,
category_id: 1,
cityId: 1,
categoryId: 1,
tags: ['General', 'health', 'butter'],
};

const resource3 = {
src_name: 'Boop',
src_description: 'You call we boop',
const mockResource3 = {
srcName: 'Boop',
srcDescription: 'You call we boop',
info: ['000-825-0000', '000-825-3333', '[email protected]'],
city_id: 1,
category_id: 1,
cityId: 1,
categoryId: 1,
tags: ['General', 'boop', 'butter'],
};

describe('demo CRUD routes', () => {
describe('resources routes', () => {
beforeEach(() => {
return setup(pool);
});
Expand All @@ -43,72 +43,73 @@ describe('demo CRUD routes', () => {
});

it('tests create resource route', async () => {
const res = await request(app).post('/api/v1/resources').send(resource);
const res = await request(app).post('/api/v1/resources').send(mockResource1);

expect(res.body).toEqual({
id: '1',
...resource,
...mockResource1,
});
});

it('gets a resource by id via GET', async () => {
const currentResrc = await Resource.insert(resource);
const resource = await Resource.insert(mockResource1);

const res = await request(app).get(`/api/v1/resources/${currentResrc.id}`);
const res = await request(app).get(`/api/v1/resources/${resource.id}`);

expect(res.body).toEqual({
id: '1',
...currentResrc,
...resource,
});
});

it('gets a list of resources via GET', async () => {

await Resource.insert(resource);
await Resource.insert(resource2);
await Resource.insert(resource3);

await Resource.insert(mockResource1);
await Resource.insert(mockResource2);
await Resource.insert(mockResource3);

const res = await request(app).get('/api/v1/resources');

expect(res.body).toEqual(expect.arrayContaining([
{
id: '1',
...resource,
},
{
id: '2',
...resource2,
},
{
id: '3',
...resource3,
},
]));
expect(res.body).toEqual(
expect.arrayContaining([
{
id: '1',
...mockResource1,
},
{
id: '2',
...mockResource2,
},
{
id: '3',
...mockResource3,
},
])
);
});

it('updates a resource via PUT', async () => {
const resrc = await Resource.insert(resource);
const resource = await Resource.insert(mockResource1);

const res = await request(app)
.put(`/api/v1/resources/${resrc.id}`)
.send({ src_description: 'this is new' });
expect(res.body).toEqual({
.put(`/api/v1/resources/${resource.id}`)
.send({ srcDescription: 'this is new' });

expect(res.body).toEqual({
id: 1,
...resrc,
src_description: 'this is new'
...resource,
srcDescription: 'this is new',
});
});

it('deletes an existing resource by id via DELETE', async () => {
const resrc = await Resource.insert(resource);
const resource = await Resource.insert(mockResource1);

const res = await request(app)
.delete(`/api/v1/resources/${resrc.id}`);
const res = await request(app).delete(
`/api/v1/resources/${resource.id}`
);

expect(res.body).toEqual({
message: `${resrc.src_name} has been deleted!`
expect(res.body).toEqual({
message: `${resource.srcName} has been deleted!`,
});
});
});
Loading