Skip to content

Commit

Permalink
Merge pull request #65 from developmentseed/enhance/cypress-api
Browse files Browse the repository at this point in the history
Move mock API routes payloads into separate files
  • Loading branch information
vgeorge authored Jan 3, 2024
2 parents 2e5d60b + b230334 commit e864bef
Show file tree
Hide file tree
Showing 47 changed files with 1,075 additions and 1,218 deletions.
2 changes: 2 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = defineConfig({
experimentalFetchPolyfill: true,
chromeWebSecurity: false,
defaultCommandTimeout: 7000,
video: false,
viewportHeight: 800,
e2e: {
baseUrl: 'http://localhost:9000/',
excludeSpecPattern: [
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/about.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('The About Page', () => {
it('successfully loads', () => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.visit('/about');
cy.get('body');
cy.get('header');
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/auth.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const restApiEndpoint = Cypress.config('restApiEndpoint');

describe('The app header', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
});

it('shows the account button when logged in', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/home.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// / <reference types="Cypress" />
describe('The Home Page', () => {
it('successfully loads', () => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.visit('/');
cy.get('body');
});
Expand Down
6 changes: 3 additions & 3 deletions cypress/e2e/project/aois.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('Loads AOIs', () => {
let map;

beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();
cy.visit('/project/new');

Expand Down Expand Up @@ -344,7 +344,7 @@ describe('Loads AOIs', () => {

describe('Load AOIs and draw a third one', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
});

it('Should show the confirmation modal if switching to another AOI before running prediction', () => {
Expand Down Expand Up @@ -392,7 +392,7 @@ describe('Load AOIs and draw a third one', () => {

describe('Can delete AOIs', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
});

it('Displays delete button on header', () => {
Expand Down
6 changes: 4 additions & 2 deletions cypress/e2e/project/batch.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const restApiEndpoint = Cypress.config('restApiEndpoint');

describe('Batch predictions', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.mockModelApiRoutes();
cy.mockProjectEndpoints();

const paginatedBatchList = (req) => {
let total = 25;
Expand Down Expand Up @@ -336,7 +338,7 @@ describe('Batch predictions', () => {
// phase: 'Running',
// },
// };
// cy.mockApiRoutes();
// cy.mockCommonApiRoutes();
// /**
// * GET /project/:id/instance/:id
// */
Expand Down
4 changes: 3 additions & 1 deletion cypress/e2e/project/delete.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe('Delete a project', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.mockModelApiRoutes();
cy.mockProjectEndpoints();
cy.fakeLogin();
cy.visit('/profile/projects/1');
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/gpu.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const instance = {

describe('Test running GPUs', () => {
it('Run project on GPU', () => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin('user', { gpu: true });

// Active instances list
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/keyboard-shortcuts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const instance = {

describe('Test keyboard shortcuts', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();
cy.setWebsocketWorkflow('websocket-workflow/retrain.json');

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/layers-panel.cy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe('Open existing project', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
});

it('successfully loads', () => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/new.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const aoi1 = {

describe('Create new project', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();

// Active instances list
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/panel.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const instance = {

describe('Panel functions', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();
cy.setWebsocketWorkflow('websocket-workflow/retrain.json');

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/retrain.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const instance = {

describe('Retrain existing project', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();

/**
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/project/sec-panel.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const aoiNoStats = {

describe('Panel functions', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
cy.fakeLogin();
cy.setWebsocketWorkflow('websocket-workflow/retrain.json');

Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/users.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { paginatedList } from '../support/commands/mock-api-routes/utils';

describe('The app header', () => {
beforeEach(() => {
cy.mockApiRoutes();
cy.mockCommonApiRoutes();
});

it('shows the account button when logged in', () => {
Expand Down
50 changes: 50 additions & 0 deletions cypress/support/commands/mock-api-routes/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { interceptHostname, interceptUrl, interceptApiRoute } from './utils';

import apiIndex from '../mock-api-routes/fixtures/index.json';
import apiHealth from '../mock-api-routes/fixtures/health.json';
import imageryIndex from '../mock-api-routes/fixtures/imagery.json';
import mosaicIndex from '../mock-api-routes/fixtures/mosaic/index.json';
import mosaicNaipLatest from '../mock-api-routes/fixtures/mosaic/naip.latest.json';

const restApiEndpoint = Cypress.config('restApiEndpoint');

Cypress.Commands.add('mockCommonApiRoutes', () => {
// OSM Tiles
['a', 'b', 'c'].forEach((subdomain) => {
interceptHostname(`${subdomain}.tile.openstreetmap.org`, {
fixture: 'tiles/osm-tile.png',
});
});

// Fake Imagery Layer
interceptUrl('https://tiles.lulc.ds.io/**', 'GET', {
fixture: 'tiles/imagery-tile.png',
});

// API Health
interceptUrl(`${restApiEndpoint}/health`, 'GET', apiHealth);

// API Limits
interceptApiRoute('', 'GET', apiIndex);

// Mosaic
interceptApiRoute('mosaic/naip.latest', 'GET', mosaicNaipLatest);

// Geocoder
interceptUrl(
'https://dev.virtualearth.net/REST/v1/Locations/*?*',
'GET',
{ fixture: 'geocoder/dc.json' },
'reverseGeocodeCity'
);
interceptUrl(
'https://dev.virtualearth.net/REST/v1/Locations/40.36315736436661,-77.7938461303711?*',
'GET',
{ fixture: 'geocoder/rural.json' },
'reverseGeocodeRural'
);

// Imagery and Mosaic
interceptApiRoute('imagery', 'GET', imageryIndex);
interceptApiRoute('mosaic', 'GET', mosaicIndex);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "healthy": true, "message": "Good to go" }
45 changes: 45 additions & 0 deletions cypress/support/commands/mock-api-routes/fixtures/imagery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"body": {
"total": 2,
"imagery_sources": [
{
"id": 1,
"created": 1675835884757,
"updated": 1675835884757,
"name": "NAIP",
"bounds": {
"type": "Polygon",
"coordinates": [
[
[-180, -85.0511287798066],
[-180, 85.0511287798066],
[180, 85.0511287798066],
[180, -85.0511287798066],
[-180, -85.0511287798066]
]
],
"bounds": [-180, -85.0511287798066, 180, 85.0511287798066]
}
},
{
"id": 2,
"created": 1675866091377,
"updated": 1675866091377,
"name": "Sentinel-2",
"bounds": {
"type": "Polygon",
"coordinates": [
[
[-180, -85.0511287798066],
[-180, 85.0511287798066],
[180, 85.0511287798066],
[180, -85.0511287798066],
[-180, -85.0511287798066]
]
],
"bounds": [-180, -85.0511287798066, 180, 85.0511287798066]
}
}
]
}
}
12 changes: 12 additions & 0 deletions cypress/support/commands/mock-api-routes/fixtures/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1.0.0",
"limits": {
"live_inference": 10000000,
"max_inference": 100000000,
"instance_window": 600,
"total_cpus": 15,
"active_cpus": 5,
"total_gpus": 15,
"active_gpus": 5
}
}
52 changes: 52 additions & 0 deletions cypress/support/commands/mock-api-routes/fixtures/model/1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"id": 1,
"created": 1636558577692,
"active": true,
"imagery_source_id": 1,
"uid": 4,
"name": "Midwest 7 Class",
"meta": {
"name": "Midwest 7 Class",
"imagery": "NAIP",
"f1_score": {
"tree": 0.77,
"grass": 0.72,
"roads": 0.8,
"water": 0.63,
"bare soil": 0.16,
"buildings": 0.73,
"other impervious": 0.73
},
"description": "Midwest Combined multi-year",
"f1_weighted": 0.738,
"label_sources": "uvm",
"training_area": 20802.340261,
"training_data_aoi": "https://mvpmodels.blob.core.windows.net/midwest-multi-year/midwest_aoi.geojson",
"class_distribution": {
"tree": 0.43,
"grass": 0.28,
"roads": 0.06,
"water": 0.01,
"bare soil": 0.01,
"buildings": 0.09,
"other impervious": 0.13
},
"imagery_resolution": "100 cm"
},
"classes": [
{ "name": "tree", "color": "#6CA966" },
{ "name": "grass", "color": "#D0F3AB" },
{ "name": "bare soil", "color": "#D2AD74" },
{ "name": "water", "color": "#486DA2" },
{ "name": "buildings", "color": "#F10100" },
{ "name": "roads", "color": "#FFC300" },
{ "name": "other impervious", "color": "#FF5733" }
],
"bounds": [
-83.25599304179488,
41.246646145864226,
-81.37080774185067,
42.44198353133044
],
"storage": true
}
47 changes: 47 additions & 0 deletions cypress/support/commands/mock-api-routes/fixtures/model/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": 2,
"created": 1675854437985,
"active": true,
"imagery_source_id": 2,
"uid": 41,
"name": "srm-rm-model-02",
"meta": {
"imagery": "sentinel-2",
"f1_score": {
"Agua": 0.5,
"Bosque": 0.5,
"Pastos": 0.5,
"Selvas": 0.5,
"Urbano": 0.5,
"Agricultura": 0.5,
"Suelo desnudo": 0.5,
"Sin vegetación aparente": 0.5
},
"description": "Sentinel Model test",
"f1_weighted": 0.6,
"label_sources": "RM",
"class_distribution": {
"Agua": 0.5,
"Bosque": 0.5,
"Pastos": 0.5,
"Selvas": 0.5,
"Urbano": 0.5,
"Agricultura": 0.5,
"Suelo desnudo": 0.5,
"Sin vegetación aparente": 0.5
},
"imagery_resolution": "14"
},
"classes": [
{ "name": "Bosque", "color": "#14d921" },
{ "name": "Selvas", "color": "#9aec3f" },
{ "name": "Pastos", "color": "#d8ec49" },
{ "name": "Agricultura", "color": "#f3e48b" },
{ "name": "Urbano", "color": "#f3f5f2" },
{ "name": "Sin vegetación aparente", "color": "#54d4d1" },
{ "name": "Agua", "color": "#2237d9" },
{ "name": "Suelo desnudo", "color": "#842ff8" }
],
"bounds": [-180, -90, 180, 90],
"storage": true
}
Loading

0 comments on commit e864bef

Please sign in to comment.