forked from TimonKK/adwords-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
budgetService.spec.js
executable file
·99 lines (89 loc) · 2.67 KB
/
budgetService.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var
async = require('async'),
expect = require('expect'),
uuid = require('uuid');
describe('BudgetService', function() {
var AdWords = require('../..');
var service = new AdWords.BudgetService();
it('should provide a service description', function(done) {
service.getClient(function(err, client) {
expect(err).toNotExist();
expect(service.description).toExist();
return done(err);
});
});
it('should get budgets', function(done) {
var selector = new AdWords.Selector.model({
fields: service.selectable,
ordering: [{field: 'BudgetName', sortOrder: 'ASCENDING'}]
});
service.get(
process.env.ADWORDS_CLIENT_CUSTOMER_ID,
selector,
function(err, results) {
expect(err).toNotExist();
expect(results.entries).toExist();
return done(err);
}
);
});
it('should create, set, and remove a budget', function(done) {
var budget = null;
async.series(
[
// Add budget
function(cb) {
var operand = new service.Model({
name: 'TEST-' + uuid.v4(),
amount: {microAmount: '10000000'},
status: 'ENABLED'
});
service.mutateAdd(
process.env.ADWORDS_TEST_ACCOUNT_ID,
operand,
function(err, results) {
expect(err).toNotExist();
expect(results.value).toExist();
expect(results.value.length).toEqual(1);
budget = results.value.pop();
return cb(err, budget);
}
);
},
// Set budget amount
function(cb) {
budget = new service.Model(budget);
budget.set('amount', {microAmount: '20000000'});
service.mutateSet(
process.env.ADWORDS_TEST_ACCOUNT_ID,
budget,
function(err, results) {
expect(err).toNotExist();
expect(results.value).toExist();
expect(results.value.length).toEqual(1);
newBudget = results.value.pop();
expect(newBudget.amount.microAmount).toEqual('20000000');
return cb(err, newBudget);
}
);
},
// Remove budget
function(cb) {
service.mutateRemove(
process.env.ADWORDS_TEST_ACCOUNT_ID,
budget,
function(err, results) {
expect(err).toNotExist();
expect(results.value).toExist();
expect(results.value.length).toEqual(1);
return cb(err);
}
);
}
],
function(err, results) {
done(err);
}
);
});
});