IEEE.org
|
IEEE Xplore Digital Library
|
IEEE Standards
|
IEEE Spectrum
|
More Sites
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Open at RIT
My Conservation Life
Conservation360
Commits
7004ca53
Unverified
Commit
7004ca53
authored
Feb 23, 2020
by
tilley14
Committed by
GitHub
Feb 23, 2020
Browse files
Merge pull request #77 from my-conservation-life/export-headers
Export headers
parents
09448e6c
575b890b
Changes
10
Hide whitespace changes
Inline
Side-by-side
db/api/tests/endpoints/assetDefinition.test.js
View file @
7004ca53
...
...
@@ -97,6 +97,66 @@ describe('GET assetTypes', () => {
});
});
describe
(
'
POST assetPropTypes
'
,
()
=>
{
beforeAll
(
async
()
=>
{
jest
.
setTimeout
(
30000
);
await
setup
();
// create some default asset types
await
loadSQL
(
'
../schema/sample-data-assetTypes.sql
'
);
});
afterAll
(
async
()
=>
{
await
teardown
();
});
it
(
'
gets all asset property types
'
,
()
=>
{
return
request
(
app
)
.
post
(
'
/api/v1/assetPropTypes
'
)
.
expect
(
200
)
.
then
((
res
)
=>
{
expect
(
res
.
body
.
rows
).
toEqual
(
expect
.
arrayContaining
([
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE1
),
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE2
),
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE3
)
])
);
expect
(
res
.
body
.
rows
).
toHaveLength
(
3
);
});
});
});
describe
(
'
POST assetPropsByTypeID
'
,
()
=>
{
beforeAll
(
async
()
=>
{
jest
.
setTimeout
(
30000
);
await
setup
();
// create some default asset types
await
loadSQL
(
'
../schema/sample-data-assetTypes.sql
'
);
});
afterAll
(
async
()
=>
{
await
teardown
();
});
it
(
'
gets all asset property types
'
,
()
=>
{
return
request
(
app
)
.
post
(
'
/api/v1/assetPropsByTypeID
'
)
.
expect
(
200
)
.
then
((
res
)
=>
{
expect
(
res
.
body
.
rows
).
toEqual
(
expect
.
arrayContaining
([
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE1
),
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE2
),
expect
.
objectContaining
(
EXPECTED_ASSET_TYPE3
)
])
);
expect
(
res
.
body
.
rows
).
toHaveLength
(
3
);
});
});
});
// TODO - tests for PUT CSV endpoint
describe
(
'
PUT CSV
'
,
()
=>
{
...
...
db/api/v1/controllers/__tests__/assetDefinitions.controller.test.js
View file @
7004ca53
const
{
getAssetTypes
}
=
require
(
'
../assetDefinitions.controller
'
);
const
{
getAssetTypes
,
getAssetPropsByTypeID
,
getAssetPropTypes
}
=
require
(
'
../assetDefinitions.controller
'
);
const
assetDefinitionsDb
=
require
(
'
../../db/assetDefinitions.db
'
);
describe
(
'
assetDefinitions.controller.getAssetTypes
'
,
()
=>
{
...
...
@@ -27,6 +27,62 @@ describe('assetDefinitions.controller.getAssetTypes', () => {
});
});
describe
(
'
assetDefinitions.controller.getAssetPropsByTypeID
'
,
()
=>
{
let
req
;
let
res
;
let
next
;
let
expectedAssetTypes
;
let
data
;
beforeEach
(()
=>
{
req
=
{
'
body
'
:
{
}
};
res
=
{
json
:
jest
.
fn
()
};
next
=
jest
.
fn
();
expectedAssetTypes
=
[{}];
data
=
{
rows
:
expectedAssetTypes
};
assetDefinitionsDb
.
findAssetPropsByTypeID
=
jest
.
fn
(
async
()
=>
data
);
});
it
(
'
returns all asset types in DB
'
,
async
()
=>
{
await
getAssetPropsByTypeID
(
req
,
res
,
next
);
expect
(
res
.
json
).
toHaveBeenCalledWith
(
data
);
});
});
describe
(
'
assetDefinitions.controller.getAssetPropsTypes
'
,
()
=>
{
let
req
;
let
res
;
let
next
;
let
expectedAssetTypes
;
let
data
;
beforeEach
(()
=>
{
req
=
{};
res
=
{
json
:
jest
.
fn
()
};
next
=
jest
.
fn
();
expectedAssetTypes
=
[{}];
data
=
{
rows
:
expectedAssetTypes
};
assetDefinitionsDb
.
findAssetPropTypes
=
jest
.
fn
(
async
()
=>
data
);
});
it
(
'
returns all asset types in DB
'
,
async
()
=>
{
await
getAssetPropTypes
(
req
,
res
,
next
);
expect
(
res
.
json
).
toHaveBeenCalledWith
(
data
);
});
});
describe
(
'
assetDefinitions.controller.storeCSV
'
,
()
=>
{
let
req
;
let
res
;
...
...
db/api/v1/db/__tests__/assetDefinitions.db.test.js
View file @
7004ca53
...
...
@@ -171,5 +171,43 @@ describe('assetDefinitions.db.storeCSV', () => {
global
.
dbPool
.
connect
=
jest
.
fn
(
async
()
=>
{
return
client
;
});
});
describe
(
'
assetDefinitions.db.findAssetTypes
'
,
()
=>
{
let
rows
;
let
query
;
beforeEach
(()
=>
{
rows
=
[{}];
query
=
jest
.
fn
(
async
()
=>
rows
);
global
.
dbPool
=
{
query
};
});
it
(
'
finds all asset types in the database
'
,
async
()
=>
{
const
actualRows
=
await
findAssetTypes
();
expect
(
actualRows
).
toEqual
(
rows
);
expect
(
query
).
toHaveBeenCalledWith
(
expect
.
stringContaining
(
'
asset_type
'
));
});
});
describe
(
'
assetDefinitions.db.findAssetPropByTypeID
'
,
()
=>
{
let
rows
;
let
query
;
let
assetTypeId
;
beforeEach
(()
=>
{
rows
=
[{}];
query
=
jest
.
fn
(
async
()
=>
rows
);
global
.
dbPool
=
{
query
};
assetTypeId
=
1
;
});
it
(
'
finds all properties associated with the asset type ID given
'
,
async
()
=>
{
const
actualRows
=
await
findAssetPropTypes
(
assetTypeId
);
expect
(
actualRows
).
toEqual
(
rows
);
});
});
// TODO tests for storeCSV function
});
salesforce/my-conservation-life/force-app/main/default/lwc/controllers/__tests__/assetDefinitionsController.test.js
View file @
7004ca53
...
...
@@ -21,6 +21,43 @@ describe('assetDefinitions.findAssetTypes', () => {
});
});
describe
(
'
assetDefinitions.findAssetPropTypes
'
,
()
=>
{
const
EXPECTED_ASSET_PROP_TYPES
=
[];
let
fetch
;
let
URL
=
utils
.
URL
+
'
assetPropTypes
'
beforeEach
(()
=>
{
fetch
=
createMockFetch
(
EXPECTED_ASSET_PROP_TYPES
);
global
.
fetch
=
fetch
;
});
it
(
'
finds all the asset properties for a given asset type
'
,
async
()
=>
{
const
assetPropTypes
=
await
assetDefinitions
.
fetchAssetPropTypes
(
1
);
expect
(
fetch
.
mock
.
calls
[
0
][
0
]).
toBe
(
URL
);
expect
(
fetch
.
mock
.
calls
[
0
][
1
]).
toEqual
(
expect
.
objectContaining
(
1
));
expect
(
assetPropTypes
).
toEqual
(
EXPECTED_ASSET_PROP_TYPES
);
});
});
describe
(
'
assetDefinitions.findAssetPropsByTypeID
'
,
()
=>
{
const
EXPECTED_ASSET_PROPERTIES
=
[];
let
fetch
;
let
URL
=
utils
.
URL
+
'
assetPropsByTypeID
'
;
beforeEach
(()
=>
{
fetch
=
createMockFetch
(
EXPECTED_ASSET_PROPERTIES
);
global
.
fetch
=
fetch
;
});
it
(
'
finds all the asset properties for a given type of asset
'
,
async
()
=>
{
const
assetPropsByTypeID
=
await
assetDefinitions
.
fetchAssetPropsByTypeID
(
1
);
expect
(
fetch
.
mock
.
calls
[
0
][
0
]).
toBe
(
URL
);
expect
(
assetPropsByTypeID
).
toEqual
(
EXPECTED_ASSET_PROPERTIES
);
});
});
describe
(
'
assetDefinitions.sendCSV
'
,
()
=>
{
const
EXPECTED_RESPONSE
=
Promise
.
resolve
();
let
fetch
;
...
...
salesforce/my-conservation-life/force-app/main/default/lwc/exportCSV/exportCSV.js-meta.xml
View file @
7004ca53
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle
xmlns=
"http://soap.sforce.com/2006/04/metadata"
fqn=
"exportCSV"
>
<apiVersion>
4
6
.0
</apiVersion>
<apiVersion>
4
7
.0
</apiVersion>
<isExposed>
true
</isExposed>
<targets>
<target>
lightning__AppPage
</target>
...
...
salesforce/my-conservation-life/force-app/main/default/lwc/exportHeaders/exportHeaders.html
0 → 100755
View file @
7004ca53
<template>
<lightning:layout
horizontalalign=
"space"
>
<lightning:layoutItem
size=
"10"
>
<lightning-combobox
name=
"datasource"
label=
"Export a template CSV"
value=
{value}
placeholder=
{value}
options=
{combo_options}
onchange=
{handleChange}
></lightning-combobox>
</lightning:layoutItem>
<br/>
<lightning:layoutItem
size=
"2"
>
<lightning-button
variant=
"success"
label=
"Download"
onclick=
{download}
></lightning-button>
</lightning:layoutItem>
</lightning:layout>
</template>
salesforce/my-conservation-life/force-app/main/default/lwc/exportHeaders/exportHeaders.js
0 → 100755
View file @
7004ca53
import
{
LightningElement
,
track
}
from
'
lwc
'
;
import
{
assetDefinitions
}
from
'
c/controllers
'
;
export
default
class
ExportHeaders
extends
LightningElement
{
@
track
value
=
'
Select an asset type...
'
;
@
track
valueID
=
null
;
@
track
placeholder
=
'
N/A
'
;
@
track
combo_options
=
[];
/**
* Sets the combobox options.
*/
connectedCallback
()
{
var
i
;
assetDefinitions
.
fetchAssetTypes
()
.
then
(
data
=>
{
var
temp_options
=
[];
for
(
i
=
0
;
i
<
data
.
rows
.
length
;
i
++
)
{
temp_options
.
push
({
'
label
'
:
data
.
rows
[
i
][
'
name
'
]
+
'
:
'
+
data
.
rows
[
i
][
'
id
'
],
'
value
'
:
data
.
rows
[
i
][
'
name
'
]
+
'
:
'
+
data
.
rows
[
i
][
'
id
'
]
});
}
this
.
combo_options
=
temp_options
;
})
.
catch
(
e
=>
{
console
.
log
(
'
Exception:
'
,
e
);
});
}
/**
* Event handler for when something is selected from the combobox.
* @param {*} event - the event object
*/
handleChange
(
event
)
{
this
.
value
=
event
.
detail
.
value
;
this
.
valueID
=
event
.
detail
.
value
.
split
(
'
:
'
)[
1
].
trimLeft
();
}
/**
* Event handler for when the download button is pressed.
*/
download
()
{
var
i
;
var
csv_data
=
''
;
var
rows
=
[];
var
hiddenElement
;
assetDefinitions
.
fetchAssetPropTypes
(
this
.
valueID
)
.
then
(
properties
=>
{
rows
=
[
'
asset_id
'
];
for
(
i
=
0
;
i
<
properties
.
rows
.
length
;
i
++
)
{
rows
.
push
(
properties
.
rows
[
i
][
'
name
'
]);
}
csv_data
+=
rows
.
join
(
'
,
'
)
+
'
\n
'
;
// Creates the CSV file and downloads it.
hiddenElement
=
document
.
createElement
(
'
a
'
);
hiddenElement
.
href
=
'
data:text/csv;charset=utf-8,
'
+
encodeURI
(
csv_data
);
hiddenElement
.
target
=
'
_blank
'
;
hiddenElement
.
download
=
this
.
value
+
'
_template.csv
'
;
hiddenElement
.
click
();
})
.
catch
(
e
=>
{
console
.
log
(
'
Exception:
'
,
e
);
});
}
}
salesforce/my-conservation-life/force-app/main/default/lwc/exportHeaders/exportHeaders.js-meta.xml
0 → 100755
View file @
7004ca53
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle
xmlns=
"http://soap.sforce.com/2006/04/metadata"
>
<apiVersion>
47.0
</apiVersion>
<isExposed>
true
</isExposed>
<targets>
<target>
lightning__AppPage
</target>
<target>
lightning__RecordPage
</target>
<target>
lightning__HomePage
</target>
</targets>
</LightningComponentBundle>
salesforce/my-conservation-life/force-app/main/default/lwc/utils/connection.js
View file @
7004ca53
const
URL
=
'
https://my-conservation-life.herokuapp.com/api/v1/
'
;
const
URL
=
'
https://my-conservation-life
-dev1
.herokuapp.com/api/v1/
'
;
export
{
URL
};
salesforce/my-conservation-life/sfdx-project.json
View file @
7004ca53
...
...
@@ -7,5 +7,5 @@
],
"namespace"
:
""
,
"sfdcLoginUrl"
:
"https://login.salesforce.com"
,
"sourceApiVersion"
:
"4
8
.0"
"sourceApiVersion"
:
"4
7
.0"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment